views:

830

answers:

2

From one apache server file_get_contents returns the contents of a url straight away. On another apache server file_get contents won't return the contents of the same url until the keep-alive limit of the server hosting that url has been expired. The 2 php servers are retrieving the same url but through different network routes. What could be causing one php installation to wait for the remote keep-alive limit before returning?

A: 

I'm not totally familiar with that php function, however i have seen similar situations caused by the output not being flushed back to the stream. I believe data is usually flushed to the stream once it reaches a certain size or when the stream is closed. It's possible this size is configured differently on each of the php servers you are using, causing the different effect. It might be worth trying to call flush() straight after your call to file_get_contents. Hope this helps.

Jarod Elliott
+1  A: 

Does using fopen manually work faster?

Rather than spending hours working out why file_get_contents doesn't work, you might be better-off swapping it out.

If fopen isn't any faster, there's probably a config or filesystem issue. If it is faster, it's likely a php.ini issue.

Oli