参考文献
swoole下载:github.com/swoole/swoo…
进行安装
下载软件
wget https://github.com/swoole/swoole-src/archive/refs/tags/v4.6.4.tar.gz
# 解压
[root@VM-0-15-centos local]# tar -zxvf swoole-src-4.6.4.tar.gz
# 重命名
[root@VM-0-15-centos local]# mv swoole-src-4.6.4 swoole-src
编译安装
cd swoole-src
/usr/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
Tips:
如果你的 php-config 没有安装在 /usr/local/php/bin 目录下,可以用 find / -name php-conf 搜索后修改
开启swoole扩展
编译安装到系统成功后,需要在 php.ini 中加入一行 extension=swoole.so 来启用 Swoole 扩展
extension=swoole.so
查看测试
扩展查看
php -m |grep swoole
swoole
php代码测试
<?php
$http = new Swoole\Http\Server("0.0.0.0", 9501);
$http->on("start", function ($server) {
echo "Swoole http server is started at http://127.0.0.1:9501\n";
});
$http->on("request", function ($request, $response) {
$response->header("Content-Type", "text/plain");
$response->end("Hello World\n");
});
$http->start();
然后 PHP 运行该文件
[root@VM-0-15-centos swoole_s]# php swoole.php
Swoole http server is started at http://127.0.0.1:9501
浏览器访问