本篇内容介绍了“如何在docker中搭建swoole环境”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
一、搭建swoole环境
拉取镜像docker pull phpswoole/swoole:4.5.9-php7.4
测试镜像环境:docker run --rm phpswoole/swoole:4.5.9-php7.4 "php -m"docker run --rm phpswoole/swoole:4.5.9-php7.4 "php --ri swoole"docker run --rm phpswoole/swoole:4.5.9-php7.4 "composer --version"
二、测试
启动容器docker run --rm -p 8000:9501 --name swoole -v /home/malina/project/swoole:/var/www phpswoole/swoole:4.5.9-php7.4
在/home/malina/project/swoole中编写server.php代码<?php$server = new Swoole\Server('0.0.0.0', 9504);$server->on('Connect', function ($server, $fd){ echo "client:connect\n";});$server->on('Receive', function ($server, $fd, $reactor_id, $data){ $server->send($fd, "Server:{$data}");});$server->on("Close", function ($server, $fd){ echo "Client:Close\n";});$server->start();
容器里执行:php server.php打开新窗口测试:curl http://127.0.0.1:8000
“如何在docker中搭建swoole环境”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注编程网网站,小编将为大家输出更多高质量的实用文章!