Home >PHP Framework >Swoole >swoole has several processes by default
Swoole process structure
The efficiency of Swoole is not only that the bottom layer is written in c, but its process structure model also makes it possible To handle business efficiently, we want to learn in depth and understand it when used in actual scenarios. Let’s take a look at the structure diagram first (recommended learning: swoole video tutorial)
First of all, let’s introduce what the various processes of swoole do.
From the names of these levels, let’s briefly talk about what the following levels do, and make a detailed description. instruction of.
Master process
The first layer is the Master process. This is the main process of swoole. This process is driven by the core events of swoole. So in this You can see in the process that it has a MainReactor [thread] and several Reactor [threads]. All swoole's event monitoring will be implemented in these threads, such as connections from clients, signal processing, etc.
Management Process Manager
To achieve the best performance, Swoole must create multiple worker processes to help process tasks, but the Worker process must fork the operation, but fork The operation is unsafe. If there is no management, many zombie processes will appear, which will affect server performance. At the same time, the worker process will be accidentally killed or exit abnormally due to program reasons. In order to ensure the stability of the service, the worker process needs to be re-created.
Worker process
The worker process belongs to the main logical process of swoole. The user processes a series of requests from the client, accepts the request packets delivered by the Reactor thread, and executes PHP The callback function processes the data to generate response data and sends it to the Reactor thread. The Reactor thread sends it to the TCP client in either asynchronous non-blocking mode or synchronous blocking mode
Task process
The taskWorker process is an asynchronous work process provided by swoole. These processes are mainly used to process some long-term synchronization tasks and deliver them in the worker process.
The above is the detailed content of swoole has several processes by default. For more information, please follow other related articles on the PHP Chinese website!