PHP.nl

stream_set_timeout

stream_set_timeout

Set timeout period on a stream

bool **stream_set_timeout** resource $stream int $seconds int $microseconds

Sets the timeout value on , expressed in the sum of and . stream``seconds``microseconds

When the stream times out, the 'timed_out' key of the array returned by is set to true, although no error/warning is generated. stream_get_meta_data

streamThe target stream.

secondsThe seconds part of the timeout to be set.

microsecondsThe microseconds part of the timeout to be set.

return.success

Voorbeeld: example

<?php
$fp = fsockopen("www.example.com", 80);
if (!$fp) {
    echo "Unable to open\n";
} else {

    fwrite($fp, "GET / HTTP/1.0\r\n\r\n");
    stream_set_timeout($fp, 2);
    $res = fread($fp, 2000);

    $info = stream_get_meta_data($fp);
    fclose($fp);

    if ($info['timed_out']) {
        echo 'Connection timed out!';
    } else {
        echo $res;
    }

}
?>

Opmerking: > This function doesn't work with advanced operations like , use with timeout parameter instead. stream_socket_recvfrom``stream_select

This function was previously called as and later but this usage is deprecated. set_socket_timeout``socket_set_timeout

fsockopen``fopen