note 19301 deleted from function.socket-read by nlopess
| From: | nlopess@php.net | Date: | Tue, 15 Feb 2005 11:53:13 +0000 |
| Subject: | note 19301 deleted from function.socket-read by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-85066@lists.php.net to get a copy of this message | ||
Note Submitter: daniel[at]lorch.cc
----
.. whereas this would be better:
while(($buf = socket_read($socket, 512)) !== false) {
// ..
}
this loop breaks if an error occurs (with type-checking of the return value). Because you don't
know how much data you will receive, you should implement a condition which breaks the loop:
while(($buf = socket_read($socket, 512)) !== false) {
$data .= $buf;
if(preg_match("'\r\n\r\n$'s", $data))
break;
}
.. which would break as soon as a <carriage return><new line><carriage
return><new line> was sent.