服务器默认安装了php7
直接使用lnmp工具包安装php5.6
使用之前的lnmp安装包,切换到root
sudo su -
运行
选择5.6
安装完成
没有安装swoole拓展
由官方https://github.com/swoole/swoole-src介绍
php5.6需要安装swoole1.x
获取swoole代码
git clone https://github.com/swoole/swoole-src.git cd swoole-src
切换到
git checkout v1.9.3-stable
先phpize
configure
完成后
make && make install
编译完成
修改php5.6 的 php.ini加入
extension=swoole.so
![](https://img2018.cnblogs.com/blog/1011411/201811/1011411-20181106190559799-1118234256.png)
安装完成
测试
新建swooletest.php
<?php $server = new SwooleHttpServer('127.0.0.1', 9501); $server->on('Request', function($request, $response) { $tcp_cli = new SwooleCoroutineClient(SWOOLE_SOCK_TCP); $tcp_cli->connect('127.0.0.1', 9906); $tcp_cli->send('test for the coroutine'); $ret = $tcp_cli->recv(5); $tcp_cli->close(); if ($ret) { $response->end(' swoole response is ok'); } else{ $response->end(" recv failed error : {$client->errCode}"); } }); $server->start();
启动测试
/usr/local/php5.6/bin/php swooletest.php
查看端口:
![](https://img2018.cnblogs.com/blog/1011411/201811/1011411-20181106190823992-1029092269.png)
php5.6swoole 拓展安装完成
php7直接执行
pecl install swoole