(PHP 4 >= 4.1.0, PHP 5, PHP 7, PHP 8) socket_set_nonblock — Sets nonblocking mode for file descriptor fd Descriptionsocket_set_nonblock(Socket When an operation (e.g. receive, send, connect, accept, ...) is performed on a non-blocking socket, the script will not pause its execution until it receives a signal or it can perform the operation. Rather, if the operation would result in a block, the called function will fail. Return Values Returns Changelog
ExamplesExample #1 socket_set_nonblock() example
This example creates a listening socket on all interfaces on port 1223 and sets the socket to See Also
kpobococ at gmail dot com ¶ 12 years ago
I'm writing a Web Server to support FastCGI. Using Unix socket to communicate with php-fpm, the non-block option cannot be set, which will cause the php-fpm response parser to access illegal memory. I've used socket() to set non-blocking options, and using fcntl() to set non-blocking options can lead to illegal memory access. Once the non-blocking options are cancelled, everything works. But my Web Server is a non-blocking event-driven model, so I have to use Unix sockets for non-blocking communications. test.cc
fastCGI/response_parser.h
fastCGI/response_parser.cc
I think the key is ResponseParser, so RequestBuilder is not posted, if necessary, I can fill it up. gdb backstrace
Without the O_NONBLOCK
the request PHP file 1.php
I expect to make Unix Socket work properly after setting up non-blocking IO. As I understand it, Unix sockets and INET sockets should behave identically on blocking. Why does this happen? Thank for you very much. |