[英]What does PHP do when calling a URL located on the same Apache server?
I have two PHP applications on the same Apache server. 我在同一个Apache服务器上有两个PHP应用程序。 At some point, application A needs to call a URL on application B.
在某些时候,应用程序A需要在应用程序B上调用URL。
So let's say a script located at http://somedomain.com/app1/action need to download http://somedomain.com/app2/action using file_get_contents()
(the domain is the same for both applications) 因此,假设位于http://somedomain.com/app1/action的脚本需要使用
file_get_contents()
下载http://somedomain.com/app2/action file_get_contents()
两个应用程序的域都相同)
I was wondering how does PHP handle this? 我想知道PHP如何处理这个? Is the request going through the whole internet, as if it was a call to an external URL?
该请求是否遍历整个Internet,就像是对外部URL的调用一样? Or is it somehow optimizing it and accessing the application on the server directly?
或者是以某种方式优化它并直接访问服务器上的应用程序?
I think it depends from your DNS resolution and is not related to PHP. 我认为这取决于您的DNS解析并且与PHP无关。
If your network is properly configured, you should be able to access the site on your local network even by calling the public url. 如果您的网络配置正确,即使通过调用公共网址,您也应该可以访问本地网络上的网站。
To be sure about your request not leaving the server, you could use the localhost
( or 127.0.0.1
) address. 为了确保您的请求不离开服务器,您可以使用
localhost
(或127.0.0.1
)地址。 You can also use the local ip address to access it over the local network. 您还可以使用本地IP地址通过本地网络访问它。
The whole internet is big. 整个互联网很大。 But it would unlikely leave the server, depending on the network layout.
但是,根据网络布局,它不太可能离开服务器。
It uses the whole TCP/IP stack of the operating system, if that's what you want to know. 它使用操作系统的整个TCP / IP堆栈,如果这是你想知道的。
If it's in the same server, it wouldn't have to resolve the DNS name if you use 127.0.0.1
instead of somedomainname.com. 如果在同一服务器上,则如果您使用
127.0.0.1
而不是somedomainname.com,则不必解析DNS名称。
Usually request do not "go out" of your server, so application B is accessed quicly by application A. 通常请求不要“离开”您的服务器,因此应用程序B可以快速访问应用程序A.
Requests can "go out" in the wild and then being routed back to your server (and that's not so good for performance) if your server DNS are not configured well (pratically, your server can't recognize itself as somedomain.com
). 如果您的服务器DNS配置不正确(通常,您的服务器无法将自身识别为
somedomain.com
),则请求可能会“狂奔”出去,然后被路由回您的服务器(这对性能不是很好)。
The request goes through every server between the source and the destination. 请求通过源和目标之间的每个服务器。 Since they are the same, that is no servers.
因为它们是相同的,所以没有服务器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.