Forum Moderators: coopster
I Have googled and founds lots of references and examples of stream_set_timeout for fsockopen, but none showing how you apply a timeout to file_get_contents which I need to use in this case.
Can anyone give me a sample of how to set a timeout on file_get_contents, as I understand that it can be applied to all PHP streams?
This does not timeout after 2 seconds:
$url ="http://www.mydomain.com";
stream_set_timeout($contents, 2);
$contents = file_get_contents($url, false);
Print $contents;
Tanx so much!
Best of luck!
P.S.:
When the stream times out, the 'timed_out' key of the array returned by stream_get_meta_data [us3.php.net]() is set to TRUE, although no error/warning is generated.
In this case you should use this to check whether or not the stream times out to begin with.
Hope this helps :)