note 71274 added to function.stream-set-timeout
| From: | (dianoga7[at]3dgo.net) | Date: | Mon, 20 Nov 2006 14:33:09 +0000 |
| Subject: | note 71274 added to function.stream-set-timeout | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-119905@lists.php.net to get a copy of this message | ||
I have found that in order to actually stop the socket from timing out the script, you must call
stream_get_meta_data and check for a timeout within the loop reading from the socket.
Example:
<?php
$sock = fsockopen($host, 80, $errno, $errstr, 30);
if(!$sock){
echo "Unable to get server status";
}else{
$out = "GET /server.php HTTP/1.1\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($sock, $out);
stream_set_blocking($fp, FALSE );
stream_set_timeout($sock, $timeout);
$info = stream_get_meta_data($sock);
while (!feof($sock) && !$info['timed_out']) {
$file .= fgets($sock, 4096);
$info = stream_get_meta_data($sock);
}
fclose($sock);
?>
----
Server IP: 66.163.161.117
Probable Submitter: 71.217.213.203
----
Manual Page -- http://www.php.net/manual/en/function.stream-set-timeout.php
Edit -- https://master.php.net/note/edit/71274
Del: integrated -- https://master.php.net/note/delete/71274/integrated
Del: useless -- https://master.php.net/note/delete/71274/useless
Del: bad code -- https://master.php.net/note/delete/71274/bad+code
Del: spam -- https://master.php.net/note/delete/71274/spam
Del: non-english -- https://master.php.net/note/delete/71274/non-english
Del: in docs -- https://master.php.net/note/delete/71274/in+docs
Del: other reasons-- https://master.php.net/note/delete/71274
Reject -- https://master.php.net/note/reject/71274
Search -- https://master.php.net/manage/user-notes.php