Home >PHP Framework >Swoole >Let's talk about how to build a swoole environment in docker
How to build a swoole environment in docker? The following article will introduce to you how to use docker to build a swoole environment. I hope it will be helpful to you!
Are you still troubled by the environment and scratching your head about compatibility? Docker can easily solve these problems. Hahaha. It turns out that docker is so powerful and solves environmental problems. I might have borrowed a new account and spent 180 yuan to buy a server in order to learn something and considered system problems. With docker, I saved another 100 yuan a year. Money, in the hot summer, I went to buy ice cream and fruits.
拉取镜像 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
The above is the detailed content of Let's talk about how to build a swoole environment in docker. For more information, please follow other related articles on the PHP Chinese website!