最近在学习swoole php扩展,苦恼于其运行环境不能在win系统下运行, 但开发代码一直在win系统上,很无奈,,,,
所以就用docker来代替,舒服~
有很多相关docker的swoole镜像,很多都是基于ubuntn或centos的基础上创建的,不好的地方就是镜像体积太大了,而alpine的很小.经过不断地google,终于找到一位大神创建的docker, 很好用~~~~
以下是我的经历和填了一个坑
缩主机: Centos7
#file: test_swoole_server.php
$http = new swoole_http_server("0.0.0.0", 9501);//注意,不是127.0.0.1 而是 0.0.0.1
$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".json_encode(['hello'=>'nihao'.time()]));
});
$http->start();
docker 镜像,此镜像包括很多php扩展,例如json: https://github.com/cmptech/auto_cmp_php_docker_server
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gettext
gmp
hash
iconv
imap
json
libxml
mbstring
mcrypt
memcached
mongodb
mysqli
mysqlnd
odbc
openssl
pcntl
pcre
PDO
pdo_dblib
pdo_mysql
PDO_ODBC
pdo_pgsql
pdo_sqlite
pgsql
Phar
posix
readline
redis
Reflection
session
shmop
SimpleXML
snmp
soap
sockets
SPL
sqlite3
ssh2
standard
swoole
sysvmsg
sysvsem
sysvshm
tidy
timezonedb
tokenizer
xml
xmlreader
xmlwriter
xsl
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcache
#运行容器, 映射端口:9501 ,存储卷 缩主机当前目录 : 容器 /root ,准备好后
#运行 php7 /root/test_swoole_server.php
docker run -ti -p 9501:9501 -v `pwd`:/root/ -d cmptech/auto_cmp_php_docker_server php7 /root/test_swoole_server.php
结果显示
[root@localhost yangqinjiang]# curl http://127.0.0.1:9501
Hello World
{"hello":"nihao1508839506"}