如何在PHP中创建WebSocket服务器
是否有任何教程或指南显示如何用PHP编写一个简单的Websockets服务器?我曾尝试在Google上寻找它,但没有找到很多。我找到了phpwebsockets,但现在已经过时了,不支持最新的协议。我尝试自己更新它,但似乎不起作用。 #!/php -q <?php /* >php -q server.php */ error_reporting(E_ALL); set_time_limit(0); ob_implicit_flush(); $master = WebSocket("localhost",12345); $sockets = array($master); $users = array(); $debug = false; while(true){ $changed = $sockets; socket_select($changed,$write=NULL,$except=NULL,NULL); foreach($changed as $socket){ if($socket==$master){ $client=socket_accept($master); if($client<0){ console("socket_accept() failed"); continue; } else{ connect($client); } } else{ $bytes = @socket_recv($socket,$buffer,2048,0); if($bytes==0){ disconnect($socket); } …