Home >PHP Framework >Swoole >Does swoole not have multi-threading?
Since the PHP language does not support multi-threading, Swoole uses multi-process mode. There is process memory isolation in multi-process mode. When global variables and super-global variables are modified in the working process, it will be invalid in other processes.
Reactor thread
The main process of Swoole\Server is a multi-threaded program. There is a very important group of threads called Reactor threads. It is the thread that actually handles TCP connections and sends and receives data.
After accepting a new connection, Swoole's main thread will assign the connection to a fixed Reactor thread, and this thread will be responsible for monitoring the socket. Read the data when the socket is readable, perform protocol analysis, and deliver the request to the Worker process. Send data to the TCP client when the socket is writable.
The allocation calculation method is fd % serv->reactor_num
Recommended learning: swoole video tutorial
The above is the detailed content of Does swoole not have multi-threading?. For more information, please follow other related articles on the PHP Chinese website!