from the manual
$fp = fsockopen("", 80);
if(!$fp) {
    echo "Unable to open\n";
} else {
    fputs($fp,"GET / HTTP/1.0\n\n");
    $start = time();
    socket_set_timeout($fp, 2);
    $res = fread($fp, 2000);
//    var_dump(socket_get_status($fp));
    print $res;
this will grab a file too using the socket functions, the
socket_set_timeout()'s first param is expected to be a socket handle.

"Jean-Arthur Silve" <[EMAIL PROTECTED]> wrote in message
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 :


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);
if ($f==false)
         // Timed out
         // ok

Thank you !



4, place Félix Eboue
75583 Paris Cedex 12
Tel : 01 44 67 05 05
Fax : 01 44 67 05 19
Web :

PHP General Mailing List (
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