#After the swoole process is closed, you can use the Server->reload method to restart it.
Server->reload method introduction:
Restart all Worker/Task processes.
bool Server->reload(bool $only_reload_taskworkrer = false)
$only_reload_taskworkrer Whether to restart only the Task process
A busy back-end server is processing requests at any time. If the administrator terminates/restarts the server program by killing the process, it may cause a crash. The code is terminated halfway through execution.
In this case, data inconsistency will occur. For example, in a trading system, the next section of the payment logic is shipment. It is assumed that the process is terminated after the payment logic. This will cause the user to pay the currency but not deliver the goods, and the consequences will be very serious.
Swoole provides a flexible termination/restart mechanism. The administrator only needs to send a specific signal to the Server, and the Server's Worker process can end safely.
1. SIGTERM: Send this signal to the main process/management process and the server will terminate safely
2. In PHP code, you can call $serv->shutdown() to complete this operation
3. SIGUSR1: Send SIGUSR1 signal to the main process/management process, which will restart all Worker processes smoothly
4. In PHP code, you can call $serv->reload() to complete this operation
5. Reload has a protection mechanism. When a reload is in progress, it will be discarded when a new restart signal is received.
6. If user/group is set, the Worker process may not have permission to send messages to the master The process sends information. In this case, you must use the root account and execute the kill command in the shell to restart.
7. The reload command is invalid for user processes added by addProcess
Recommended learning: swoole video tutorial
The above is the detailed content of How to restart the swoole process after it is closed. For more information, please follow other related articles on the PHP Chinese website!