I am calling a series of links using the file_get_contents()
method in a loop. Each link may take more than 15 minutes to process. Now, I worry about whether PHP's file_get_contents()
has a timeout period?
If yes, it will time out with a call and move to next link. I don't want to call the next link without the prior one finishing.
So, please tell me whether file_get_contents()
has a timeout period. The file which contains the file_get_contents()
is set to set_time_limit()
to zero (unlimited).
As @diyism mentioned, "default_socket_timeout, stream_set_timeout, and stream_context_create timeout are all the timeout of every line read/write, not the whole connection timeout." And the top answer by @stewe has failed me.
As an alternative to using
file_get_contents
, you can always usecurl
with a timeout.So here's a working code that works for calling links.
The default timeout is defined by
default_socket_timeout
ini-setting, which is 60 seconds. You can also change it on the fly:Another way to set a timeout, would be to use
stream_context_create
to set the timeout as HTTP context options of the HTTP stream wrapper in use:It is worth noting that if changing default_socket_timeout on the fly, it might be useful to restore its value after your file_get_contents call:
For me work when i change my php.ini in my host: