note 31711 deleted from function.socket-read by nlopess
| From: | nlopess@php.net | Date: | Mon, 15 Dec 2003 16:08:47 +0000 |
| Subject: | note 31711 deleted from function.socket-read by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-61990@lists.php.net to get a copy of this message | ||
Note Submitter: caesar
----
the read function causes windows to crash when someone
disconnects while the script is trying to read.
i came up with this small function that eliminates that problem:
<?
function read(&$sock,&$buff,$len){
$buff = socket_read($sock,$len,PHP_BINARY_READ);
if(strlen($buff) == $len)
return true;
else
return false;
}
?>
$sock = what ever your socket is;
$buff = has to be an already defined variable since its passed by refference
$len = the number of bytes to read
the function returns true if it still has something to read,
false if it has recieved everything