#php's existing application methods are all based on http, which is relatively weak for situations that require fast real-time response. For example, online games or push services generally need to maintain long-term communication with users. A tcp connection for real-time response and push information.
#swoole is designed to solve such application scenarios. (Recommended learning: SWOOLE Video Tutorial )
# Swoole Realization
Swoole is written in pure C, not depending on other third -party libraries .
swoole does not use libevent, so there is no need to install libevent
swoole does not rely on PHP's stream/sockets/pcntl/posix/sysvmsg and other extensions
socket Part
swoole uses the underlying socket system call.
IO event loop
The event loop of the main process uses select/poll, because there are only a few file descriptors in the main thread, just use select/poll
Use epoll/kqueue in the reactor thread/worker process
The task process does not have an event loop, and the process will cycle and block the read pipe
Many people use strace -p to view swoole The main process can only see the poll system call. The correct way to view it is strace -f -p
Multiple processes/multithreads
Multiple processes use the fork() system call
Multiple threads use pthread thread library
EventFd
Swoole uses eventfd as a mechanism for thread/inter-process message notification.
Timerfd
Swoole uses timerfd to implement the timer
SIgnalfd
signalfd is used in swoole To achieve signal shielding and processing. It can effectively avoid the problem of threads/processes being interrupted by signals and the system calling restart. The reactor thread will not receive any signals in the main process.
The above is the detailed content of What problem did swoole solve?. For more information, please follow other related articles on the PHP Chinese website!