function server() { // Note how we pass our ServerSocketClass here $server = new SocketServer("tcp://127.0.0.1:8081", "\\ServerSocketClass"); echo "Server running. Now go ahead and connect to 127.0.0.1:8081 with netcat (nc 127.0.0.1 8081)\n"; $running = true; while ($running) { // Go over the sockets that are ready to read foreach ($server->select() as $sock) { $str = $sock->read(1024); if ($str == "") { // Call close on the server rather than disconnect to free // it from the pool. $server->close($sock); } else { $sock->onData($str); } } // Do this for each loop $server->each(function ($client) { $client->onTick(); }); } }