Re: [PHP-DOC] cvs: phpdoc /en/functions network.xml From: Andrei Zmievski (andrei <email protected>)
Date: 08/23/00

On Wed, 23 Aug 2000, Ron Chmara wrote:
> +&lt;?php
> +socket_set_timeout(80,5,0)
> +// set 5 second maximum for connection over port 80
> +$fp = fopen("http://www.php.net/index.php","r");
> +if (!$fp) {
> + print"Unable to open";
> +} else {
> + print"Opened in less than 5 sec";
> +}
> +?&gt;

Uh, that example is not correct. socket_set_timeout() does not control
fopen() timeouts, but rather the timeout during reading or writing data
from or to the socket. So, you could have something like this:

$fp = fsockopen("http://php.ispi.net", 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));
    fclose($fp);
    print $res;
}

socket_get_status() will help you determine whether a timeout occurred
or not.

-Andrei

"Everything has its wonders, even darkness and silence, and I learn,
 whatever state I may be in, therein to be content." - Helen Keller