开发者

Does a cURL post to the same site leave the local network?

开发者 https://www.devze.com 2023-01-20 07:35 出处:网络
I\'m doing a PHP cURL post, using a complete URL (http://www.mysite.com), from one page to another on the same site. (I know this isn\'t the best way to do it; but for my purpose this is what I need)

I'm doing a PHP cURL post, using a complete URL (http://www.mysite.com), from one page to another on the same site. (I know this isn't the best way to do it; but for my purpose this is what I need)

My question is:

Will the cURL post still go out across the internet, do a name lookup and travel a route as though it were 开发者_Go百科a post coming from a different site. Or will the post stay on the servers local network?


There are multiple parts to the request, the dns lookup and the get or post to the site.

DNS Records are usually cached on most OSes, so it's rather unlikely that the server would have to do a dns lookup for it's own external ip, but it's possible.

As for the post, let's assume a basic layout:

Firewall         =>   DMZ Apache PHP Server (www.mysite.com)
222.xxx.xxx.123  =>   192.168.0.2

And mysite.com resolves to 222.xxx.xxx.123, then your request will go to your firewall's external interface and bounce back in. That's not terribly public traffic, but it goes out none-the less.

However, if you wanted to bypass that, you could put an entry in the host file of the server to say

127.0.0.1 mysite.com

(assuming you control the server, ie not shared hosting)


No. The post itself (unless you have multiple interfaces and your routing is totally screwed up) will not traverse the internet. Your local host ought to be able to resolve its own name as well, but there is a possibility that a DNS request will be made to determine the IP address corresponding to the name. I would hope that the network stack implementation on your system would prevent the post's packets from even hitting the wire (similar to localhost), but I wouldn't count on it.


It depends on your network setup. Many sites have a domain name pointing to the IP address of a front facing router or load balancer which forward the request to the web server.

If that's the case a request to your own site can make a round-trip to the router. Though it's unlikely that the request will go through the internet unless you have a very unusual setup (such as round robin DNS with multiple datacenters).

You can avoid the round-trip by associating the site FQDN to the loopback interface in your webserver /etc/hosts which will also save you a DNS request.

0

精彩评论

暂无评论...
验证码 换一张
取 消