Forum Moderators: coopster

Message Too Old, No Replies

file get contents - Timeout

         

crankshaft

7:46 am on Nov 9, 2006 (gmt 0)

10+ Year Member



Hello all;

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!

eelixduppy

7:01 am on Nov 10, 2006 (gmt 0)



I'm not sure if stream_set_timeout works for file_get_contents, however if it doesn't, I'm pretty sure that it works for fopen [us3.php.net], so you may want to look into that.

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 :)

vincevincevince

7:05 am on Nov 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ini_set('default_socket_timeout', $seconds);