1

I have two PHP applications on the same Apache server. At some point, application A needs to call a URL on application B.

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)

I was wondering how does PHP handle this? Is the request going through the whole internet, as if it was a call to an external URL? Or is it somehow optimizing it and accessing the application on the server directly?

3
  • 2
    "Going through the whole internet"? No request ever goes through "the whole Internet". Commented Dec 9, 2011 at 11:09
  • You probably could prevent an "internet roundtrip" by configuring your local DNS but that would probably be a question more suited for serverfault.com Commented Dec 9, 2011 at 11:13
  • @Quentin, "going through the whole internet" was an exaggeration. Let's say I call google.com from my computer, the request is going through plenty of servers. What I'm wondering is if the same thing is going to happen in the example mentioned in the post. Commented Dec 9, 2011 at 11:27

5 Answers 5

3

I think it depends from your DNS resolution and is not related to 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. You can also use the local ip address to access it over the local network.

Sign up to request clarification or add additional context in comments.

Comments

0

It uses the whole TCP/IP stack of the operating system, if that's what you want to know.

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.

Comments

0

Usually request do not "go out" of your server, so application B is accessed quicly by application 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).

Comments

0

The whole internet is big. But it would unlikely leave the server, depending on the network layout.

1 Comment

Why would it make a roundtrip to the ISP? The IP address would be bound to a network interface on the local machine.
0

The request goes through every server between the source and the destination. Since they are the same, that is no servers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.