search
HomePHP FrameworkSwooleLet'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!

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
测试镜像环境:
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"

2. Test
启动容器
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(&#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();
容器里执行:
php server.php
打开新窗口测试:
curl http://127.0.0.1:8000


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!

Statement
This article is reproduced at:learnku. If there is any infringement, please contact admin@php.cn delete

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools