-
Notifications
You must be signed in to change notification settings - Fork 258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
socket 两处阻塞有点没明白,请大佬解释一下 #25
Comments
首先是listen socket本身是阻塞的 |
恩, "listen socket 本身是阻塞" 这个我有点不明白, // 创建一个监听socket,这个一个阻塞IO的socket
$listen = socket_create( AF_INET, SOCK_STREAM, SOL_TCP );
socket_bind( $listen, '0.0.0.0', 9999 );
socket_listen( $listen );
echo "test.",PHP_EOL;
while( true ){
$connect = socket_accept( $listen );
} 如果 |
不太容易解释,我这么说如果你把listen设置为非阻塞的,那么监听期间就只能应对一个客户的链接,如果恰巧此时有第二个客户,第二个就得等了。阻塞并不是说前三行代码阻塞,而是这个listen socket(本质上是一个文件)是阻塞的,是指这个意思。 |
越来越懵了。。。 |
可能是我解释的不太好,文本表达有限。你可以去php.net查询 socket_set_nonblock函数,那上面有解释 |
好的, 谢谢解释。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: