Home > PHP Framework > Swoole > body text

Does swoole worker have event polling?

(*-*)浩
Release: 2019-12-16 09:28:08
Original
2199 people have browsed it

Does swoole worker have event polling?

Swoole provides a complete process management mechanism. When the Worker process exits abnormally, such as a fatal error in PHP, being accidentally killed by other programs, or exiting normally after reaching the max_request number. (Recommended learning: SWOOLE Video Tutorial )

The main process of the main process will re -pull the new worker process. You can write code in the Worker process like ordinary apache php or php-fpm.

swoole_server thread mode

This is the multi-threaded Worker mode. The Reactor thread handles network event polling and reads data. The obtained request is handed over to the Worker thread for processing.

Swoole provides configurable parameters to achieve m/n parameter adjustment.

In this mode onReceive can have moderate blocking operations. Multi-threaded mode is lighter than process mode, and stacks and resources can be shared between threads.

There will be synchronization problems when accessing shared memory, and the lock mechanism provided by Swoole needs to be used to protect data.

Currently, five types of lock implementations have been provided: Mutex, read-write lock, file lock, semaphore, and spin lock.

Advantages of multi-threading:

Objects and variables are shared and can be operated directly

File descriptors are shared and different threads The same resource can be operated directly

Disadvantages of multi-threading:

Requires locking when operating non-local variables, making programming difficult

a A memory error occurs in the thread, and the entire process will end.

Due to the memory error in PHP's ZendVM in the multi-threaded mode, the multi-threaded mode has been closed after v1.6.0

The above is the detailed content of Does swoole worker have event polling?. 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