note 110069 deleted from sockets.examples by danbrown
| From: | danbrown@php.net | Date: | Thu, 06 Dec 2012 15:21:42 +0000 |
| Subject: | note 110069 deleted from sockets.examples by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192368@lists.php.net to get a copy of this message | ||
Note Submitter: tomasz[hate-spam] at trejderowski dot pl
----
You have to change following lines in javier's example:
if (false === ($buf = socket_read($client, 2048, PHP_NORMAL_READ))) {
echo "socket_read() falló: razón: " .
socket_strerror(socket_last_error($client)) . "\n";
break 2;
}
with these:
if (false === ($buf = socket_read($client, 2048, PHP_NORMAL_READ))) {
echo "socket_read() falló: razón: " .
socket_strerror(socket_last_error($client)) . "\n";
unset($clients[$key]);
socket_close($client);
break;
}
if you want your TCP listener to continue, after client breaks connection.
Try to run pure javier's example, without above changes, and contact your listener with any web
browser. Since it not receive understable answer (will get echo of what it sent and this is not a
correct HTTP header, it is waiting for), it will break a connection with timeout. This will cause
javier's example to also break (exit with fatal error).
Adapting thses small changes will cause your listener, in the same situation, to only issue one or
two warnings (which could be further surpressed, if someone wants it) and continue listening, to
support other clients.