|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2002-10-22 10:19 UTC] sniper@php.net
[2002-10-23 09:47 UTC] sven dot schnitzke at t-online dot de
[2002-10-24 01:55 UTC] sniper@php.net
[2002-10-25 13:09 UTC] sven dot schnitzke at t-online dot de
[2002-10-28 07:55 UTC] iliaa@php.net
[2002-11-01 17:08 UTC] sven dot schnitzke at t-online dot de
[2002-11-07 11:07 UTC] sven dot schnitzke at t-online dot de
[2002-12-09 09:23 UTC] iliaa@php.net
[2002-12-10 05:29 UTC] sven dot schnitzke at t-online dot de
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 13:00:02 2025 UTC |
I use this with PHP 4.2.2 Win executable version: <?php // set up listener and wait for clients $listener = socket_create(AF_INET, SOCK_STREAM, 0); socket_setopt($listener, SOL_SOCKET, SO_REUSEADDR, 1); socket_bind($listener, "0.0.0.0", 1234); if (socket_listen($listener, 5); $client = array(); // monitoring loop while (true) { $read[0] = $listener; // keep track of clients for ($i = 0; $i < MAX_CLIENTS; i++) { if ($client[$i] != null) $read[$i + 1] = $client[$i]; } // watch for any socket activity $nready = socket_select($read, $null, $null, null); if (in_array($listener, $read)) { // here we have a new client for ($i = 0; $i < MAX_CLIENTS; $i++) { if ($client[$i] == null) { $client[$i] = socket_accept($listener); break; } } if (--$nready <= 0) continue; } // get data from socket(s) marked as active for ($i = 0; $i < MAX_CLIENTS; $i++) { if (in_array($client[$i], $read)) { socket_getpeername($client[$i], $host, $port); $n = socket_read($client[$i], 16300); if (strlen($n) > 0) echo "rcv from $host:$port:$n\r\n"; // else close and cleanup socket } } } This is, slightly modified, the example from the manual. Everything works fine as long as I have well-behaved clients. But if I for example try this against a telnet client and just close it without properly disconnecting before my script (by the way running in a dos box with php -f ... ) in turn dies with a page fault when getting to "socket_read". I tried to have a look at "socket_last_error" after "socket_select" but that does not help since it says: 0. "socket_select" lets loose upon the killing of the client, putting the socket into the "$read" array. So I have to look at it...