PHP is used in the project, but due to the long and time-consuming task, after the front-end is submitted, the server needs to respond asynchronously.
There are many solutions for server asynchronous, including MQ, fsocket, Swoole, etc. (Recommended learning: swoole video tutorial)
Swoole is written in pure C language and provides an asynchronous multi-threaded server in PHP language and an asynchronous TCP/UDP network client. , asynchronous MySQL, asynchronous Redis, database connection pool, AsyncTask, message queue, millisecond timer, asynchronous file reading and writing, asynchronous DNS query.
Swoole has built-in Http/WebSocket server/client and Http2.0 server.
The most important thing is that it perfectly supports the PHP language. So I used Swoole to build an asynchronous server to provide a series of tasks such as asynchronous response, push, and scheduled tasks.
Installation
Swoole is written in C language and uses compilation and installation.
The installation dependencies are:
php-5.3.10 或更高版本 gcc-4.4 或更高版本
make autoconf pcre (centos系统可以执行命令:yum install pcre-devel)
Installation method:
phpize #如果命令不存在 请在前面加上php的实际路径 ./configure make sudo make install
After the compilation is completed, it needs to be in php.ini Add extension
extension=swoole.so
The above is the detailed content of How to use swoole. For more information, please follow other related articles on the PHP Chinese website!