Home >Backend Development >PHP Tutorial >cli模式的stream_socket_accept函数问题

cli模式的stream_socket_accept函数问题

WBOY
WBOYOriginal
2016-06-23 14:20:411278browse

本帖最后由 jdgdf566 于 2013-08-30 17:41:37 编辑

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 Warning:  stream_socket_accept(): accept failed: 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。
apache下没有此问题。

回复讨论(解决方案)

防火墙放行php了没有?

防火墙放行php了没有? 没安装防火墙啊

不晓得,你的错误信息是超时,就是连接不上

查一下$errno

不晓得,你的错误信息是超时,就是连接不上

查一下$errno 确实是超时。stream_socket_accept($server)的第二个参数为0的时候并不是无限时间。应该放在循环结构里面使用这个函数。初步结论是这样。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn