1、从github拉取安装包
Release v4.8.13 · swoole/swoole-src · GitHub
2、解压压缩包
- tar -zxvf ./v4.8.13.tar.gz
-
- cd ./swoole-src-4.8.13
3、执行安装命令
- phpize && \
- ./configure && \
- make && sudo make install
4、检查swoole模块是否安装完成
php -m | grep swoole
然后通过 phpinfo() 获取到加载的swoole模块
5、通过官方的DEMO程序执行一下(这里用协程Coroutine的demo),查看是否打印正常
-
- use Swoole\Coroutine;
- use function Swoole\Coroutine\run;
-
- echo "main start\n";
- run(function () {
- echo "coro " . Coroutine::getcid() . " start\n";
- Coroutine::create(function () {
- echo "coro " . Coroutine::getcid() . " start\n";
- Coroutine::sleep(.2);
- echo "coro " . Coroutine::getcid() . " end\n";
- });
- echo "coro " . Coroutine::getcid() . " do not wait children coroutine\n";
- Coroutine::sleep(.1);
- echo "coro " . Coroutine::getcid() . " end\n";
- });
- echo "end\n";
-
- /*
- main start
- coro 1 start
- coro 2 start
- coro 1 do not wait children coroutine
- coro 1 end
- coro 2 end
- end
- */