note 73838 modified in function.stream-set-timeout by bobby

From: Date: Tue, 13 Mar 2007 19:00:41 +0000
Subject: note 73838 modified in function.stream-set-timeout by bobby
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-124415@lists.php.net to get a copy of this message
Here is a working example for loops: <?php // Timeout in seconds $timeout = 5; $fp = fsockopen("www.server.com", 80, $errno, $errstr, $timeout); if ($fp) { fwrite($fp, "GET /file.php HTTP/1.0\r\n"); fwrite($fp, "Host: www.server.com\r\n"); fwrite($fp, "Connection: Close\r\n\r\n"); stream_set_blocking($fp, TRUE); stream_set_timeout($fp,$timeout); $info = stream_get_meta_data($fp); while ((!feof($fp)) && (!$info['timed_out'])) { $data .= fgets($fp, 4096); $info = stream_get_meta_data($fp); ob_flush; flush(); } if ($info['timed_out']) { echo "Connection Timed Out!"; } else { echo $data; } } ?> --was-- Here is a working example for loops: <?php // Timeout in seconds $timeout = 5; $fp = fsockopen("teletextcars.ext.limitless.co.uk", 80, $errno, $errstr, $timeout); if ($fp) { fwrite($fp, "GET /file.php HTTP/1.0\r\n"); fwrite($fp, "Host: www.server.com\r\n"); fwrite($fp, "Connection: Close\r\n\r\n"); stream_set_blocking($fp, TRUE); stream_set_timeout($fp,$timeout); $info = stream_get_meta_data($fp); while ((!feof($fp)) && (!$info['timed_out'])) { $data .= fgets($fp, 4096); $info = stream_get_meta_data($fp); ob_flush; flush(); } if ($info['timed_out']) { echo "Connection Timed Out!"; } else { echo $data; } } ?> http://php.net/manual/en/function.stream-set-timeout.php

« previous php.notes (#124415) next »