Home > PHP Framework > Swoole > body text

Let's talk about how to build a swoole environment in docker

青灯夜游
Release: 2022-06-28 21:02:31
forward
4100 people have browsed it

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!

Let's talk about how to build a swoole environment in docker

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.

##1. Set up the swoole environment
拉取镜像
docker pull phpswoole/swoole:4.5.9-php7.4
Copy after login
测试镜像环境:
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"
Copy after login

2. Test
启动容器
docker run --rm -p 8000:9501 --name swoole -v /home/malina/project/swoole:/var/www 
phpswoole/swoole:4.5.9-php7.4
Copy after login
在/home/malina/project/swoole中编写server.php代码
<?php

$server = new Swoole\Server(&#39;0.0.0.0&#39;, 9504);
$server->on(&#39;Connect&#39;, function ($server, $fd){
  echo "client:connect\n";
});

$server->on(&#39;Receive&#39;, function ($server, $fd, $reactor_id, $data){
  $server->send($fd, "Server:{$data}");
});

$server->on("Close", function ($server, $fd){
  echo "Client:Close\n";
});

$server->start();
Copy after login
容器里执行:
php server.php
打开新窗口测试:
curl http://127.0.0.1:8000
Copy after login


The swwole server has been successfully set up here. Let’s continue by referring to the documentation and online examples.                                                                                                                                                                                                                                                                                                          

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!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!