Home >Backend Development >PHP Tutorial >cli模式的stream_socket_accept函数问题
socket
/* Open a server socket to port 1234 on localhost */$server = stream_socket_server('tcp://127.0.0.1:12345');$socket = stream_socket_accept($server); /* Grab a packet (1500 is a typical MTU size) of OOB data */ echo "Received Out-Of-Band: '" . stream_socket_recvfrom($socket, 1500, STREAM_OOB) . "'\n"; /* Take a peek at the normal in-band data, but don't comsume it. */ echo "Data: '" . stream_socket_recvfrom($socket, 1500, STREAM_PEEK) . "'\n"; /* Get the exact same packet again, but remove it from the buffer this time. */ echo "Data: '" . stream_socket_recvfrom($socket, 1500) . "'\n";/* Close it up */fclose($socket);fclose($server);
防火墙放行php了没有?
防火墙放行php了没有? 没安装防火墙啊
不晓得,你的错误信息是超时,就是连接不上
查一下$errno
不晓得,你的错误信息是超时,就是连接不上
查一下$errno 确实是超时。stream_socket_accept($server)的第二个参数为0的时候并不是无限时间。应该放在循环结构里面使用这个函数。初步结论是这样。