Jean-Arthur Silve wrote: > Hi ! > > I use the file function for accessing to pages on another server. > > It works perfectly. > > But if the server does not respond or is too long to send datas, the file > function wait too long.. > > Is there a way to tune the time out ?? I would like that id the server > does not respond, the function return in few seconds only. > > I thought to a solution using : > > set_time_limit(2); > register_shutdown_function(func); > file(myurl); > set_time_limit(30); > func(); > > In this example if the file function takes more than 2 seconds, then > func() would be called. If the file function does not time out, then then > func is called too... > > But may be there is a cleanest way to do this (I checked the manual, > somethink like socket_set_timeout), in the way that if the time function > timed out then the script continues normally, returning an error: > > tuning the time out(2); > $f=file(myurl); > if ($f==false) > // Timed out > else > // ok > ....
Use http://php.net/fsockopen, as suggested, *BUT* use the recently added optional arguments to it. You will need to have a reasonably current version of PHP to do this. The socket_blocking and socket_timeout are only useful *AFTER* you've opened the socket. -- Like music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]