Re: Time out for file()?

From: Date: Thu, 15 Nov 2001 16:40:15 +0000
Subject: Re: Time out for file()?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-74737@lists.php.net to get a copy of this message
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

« previous php.general (#74737) next »