Home > PHP Framework > Swoole > body text

How to exit swoole

Release: 2020-01-13 14:42:35
Original
2900 people have browsed it

How to exit swoole

Server->stop

Stops the current Worker process and triggers the onWorkerStop callback function immediately.

function Server->stop(int $worker_id = -1, bool $waitEvent = false);
Copy after login

Use this function instead of exit/die to end the life cycle of the Worker process

$waitEvent can control the exit strategy. The default is false to exit immediately, and set to true to wait for the event loop to be empty. Then exit

If you want to end other Worker processes, you can add worker_id as a parameter in stop or use swoole_process::kill($worker_pid)

This method is available in 1.8.2 or Available in later versions

$waitEvent is available in 1.9.19 or later versions

Asynchronous exit

The asynchronous server exits after calling stop While the process is running, there may still be events waiting. For example, Swoole\MySQL->query is used to send the SQL statement, but is still waiting for the MySQL server to return the result. If the process is forced to exit at this time, the SQL execution results will be lost.

After setting $waitEvent = true, the underlying layer will use an asynchronous safe restart strategy. First notify the Manager process and restart a new Worker to handle new requests. The current old Worker will wait for events until the event loop is empty or exceeds max_wait_time, and then exits the process to ensure the safety of asynchronous events to the greatest extent.

Recommended learning: swoole tutorial

The above is the detailed content of How to exit swoole. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template