note 110069 added to sockets.examples
| From: | tomasz | Date: | Sun, 16 Sep 2012 06:12:39 +0000 |
| Subject: | note 110069 added to sockets.examples | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-190805@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 69.147.83.197
Probable Submitter: 77.253.175.217
----
Manual Page -- http://www.php.net/manual/en/sockets.examples.php
Edit -- https://master.php.net/note/edit/110069
Del: integrated -- https://master.php.net/note/delete/110069/integrated
Del: useless -- https://master.php.net/note/delete/110069/useless
Del: bad code -- https://master.php.net/note/delete/110069/bad+code
Del: spam -- https://master.php.net/note/delete/110069/spam
Del: non-english -- https://master.php.net/note/delete/110069/non-english
Del: in docs -- https://master.php.net/note/delete/110069/in+docs
Del: other reasons-- https://master.php.net/note/delete/110069
Reject -- https://master.php.net/note/reject/110069
Search -- https://master.php.net/manage/user-notes.php