Swoole是一个多进程模式的框架(可以类比Nginx的进程模型), 当启动一个Swoole应用时, 一共会创建2 + n + m个进程, 其中n为Worker进程数, m为TaskWorker进程数, 2为一个Master进程和一个Manager进程.
Master进程为主进程, 该进程会创建Manager进程、Reactor线程等工作进/线程.
- Reactor线程实际运行epoll实例,用于accept客户端连接以及接收客户端数据
- Manager进程为管理进程,该进程的作用是创建、管理所有的Worker进程和TaskWorker进程
- Worker进程作为Swoole的工作进程, 所有的业务逻辑代码均在此进程上运行.
安装
通过pecl安装, 系统中最好已经有http2依赖(如果要使用Http2协议, 需要依赖nghttp2库, 下载nghttp2 https://github.com/tatsuhiro-t/nghttp2 后编译安装) 运行pecl需要autoconf, 如果没有会报错 Cannot find autoconf. Please check your autoconf installation
Code: Select all
sudo pecl install swoole
Code: Select all
enable sockets supports? [no] : yes
enable openssl support? [no] : yes
enable http2 support? [no] : yes
enable mysqlnd support? [no] : yes
enable postgresql coroutine client support? [no] :
Code: Select all
# php -i |grep php.ini
Configuration File (php.ini) Path => /opt/php/php7.2.10/etc
Loaded Configuration File => /opt/php/php7.2.10/etc/php.ini
Code: Select all
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
...
;extension=pdo_sqlite
;extension=pgsql
;extension=shmop
extension=mongodb
extension=swoole
Code: Select all
php -m | grep swoole