我有一个使用PHP编写的客户端,通过纯文本Unix域套接字连接到本地C服务器程序。然而,唯一能够使其正常关闭的方式是在结束套接字会话之后执行以下操作:
stream_socket_shutdown($sock, 1); // shutdown socket writing
usleep(500 * 1000); // wait for 0.5 seconds
fclose($sock); // actually close the socket (finally)
我希望能像我的C客户端一样优雅地关闭它:
shutdown(connection_fd, SHUT_WR); // tell server we've stopped sending queries
// Read from the socket until poll(connection_fd) yields POLLRDHUP / POLLHUP / POLLERR / POLLNVAL
shutdown(connection_fd, SHUT_RDWR); // tell connection we've stopped listening
close(connection_fd); // close the whole connection (finally)
然而,PHP似乎没有直接的socket poll()等价物。我该如何让PHP优雅地关闭我的本地socket?