Rene Fournier wrote:
Hi,
I have four identical command-line PHP scripts running, and each will
frequently fetch some data from another server via file_get_contents().
By frequently, I mean on average, every second.
Periodically, one of the processes (command-line PHP scripts), will fail
on file_get_contents(), with the error message:
PHP Warning: file_get_contents(http://.../): failed to open stream:
HTTP request failed!
Sometimes it's a single failure, other times, it fails repeatedly for
30-60 seconds, then starts working again. Strange, no?
At first, I thought maybe I've maxed out the server in question, but I'm
not. This problem happens on both servers that the scripts fetch data
from. And more significantly, while one process may fail at
file_get_contents(), the other processes (running identical code) on the
same box continue to execute the function (against the same servers)
without incident.
My question is, is there some resource in Mac OS X Server 10.4 (or PHP
5.2.4) that would limit a continuously running PHP script from executing
file_get_contents()? And to be clear, the failure doesn't kill the
script, and after the failure, it will start working again.
...Rene
first thing that springs to mind is some form of hardware limitation,
quite sure it's not php - could be a firewall with flood protection (or
even your own isp's anti malware set-up)
to combat it try binding the outgoing request to a random ip each time
(if you have multiple ip's on the box) [context: socket -> bindto]
next up (very unlikely) but possibly outgoing port conflict where the
previous local port is still closing whilst trying to be re-opened.
to get an ideal fix though you'll want to move away from
file_get_contents() as you're not doing things the most efficient way;
HTTP/1.1 allows you to keep a port open and make multiple requests
through the same socket/connection, simply keep the socket open and
don't send a connection: close header after the request. (i say simply
but you'll be needing to make you're own, or find a good, http handler
that allows you to write raw requests and decode the raw http responses
that come back)
best of luck; feel free to post your code incase anything jumps out as
obvious.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php