Jean-Arthur,

Your set_time_limit/shutdown function solution looks like a clever
trick.  If you can come up with that you might just as well do the
proper job with an fsockopen and socket_set_timeout.

The manual pages on fsockopen, socket_set_timeout plus the user comments
have plenty of useful examples:

http://www.php.net/manual/en/function.fsockopen.php
http://www.php.net/manual/en/function.socket-set-timeout.php

You might also want to look at socket_set_blocking as an alternative.
(Switch to non-blocking so that your "gets" always returns immediately
and then you can put in your own wait/action before trying another gets).
Check out: 

http://www.php.net/manual/en/function.socket-set-blocking.php

Either way, to write your own jasfile() to emulate file() shouldn't be more than 
10-20 lines.

An extra advantage of using fsockopen is that you can send a HEAD request
before your GET/POST to check the server/page are there.  If that
works you can then give the target server longer to serve the GET in
case the problem is just slow communications rather than a missing/slow
server.


Good Luck

George


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
> ....
> 
> Thank you !
> 
> jean-arthur
> 
> ---------------------------------------------------------------
> 
> EuroVox
> 4, place Félix Eboue
> 75583 Paris Cedex 12
> Tel : 01 44 67 05 05
> Fax : 01 44 67 05 19
> Web : http://www.eurovox.fr
> ----------------------------------------------------------------

-- 
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]

Reply via email to