最近咱们公布了 Swoole-Cli v5.0.2,这个版本减少了 opcache 扩大,使得 swoole-cli 内置的 php-fpmcli-http-server 也能够用于生产环境了,而不仅仅是作为测试应用。

目前 swoole-cli 反对了 5 种环境的二进制包可供大家抉择:

  • Linux x86-64
  • Linux arm64aarch64
  • Windows CygWin x86-64
  • macOS arm64aarch64Apple M1/M2
  • macOS x86-64
下载地址:https://www.swoole.com/download

Swoole-Cli 是齐全动态编译的,不依赖任何动态链接库,可间接下载到任意操作系统上应用,而不须要额定其余第三方包。

Docker/K8s 环境下也尤为便当,可应用最简化的 alpine linux 根底镜像,而后装置 swoole-cli 构建镜像,最终的镜像只有 100M-200M

减少 Opcache 扩大

swoole-cli --ri opcacheopcacheVersion => 8.1.12

5.0.2 版本中 swoole-cli 集成了 php-fpmcli-http-server ,但因为未反对 opcache 扩大,所以仅可用于测试环境。新的 5.0.2 版本中将 opcache 也动态编译到了 swoole-cli 二进制程序中。

这样内置的 php-fpmcli-http-server 服务就能够应用 opcacheopcache.jit 进行减速,性能达到生产可用。

强化 Cli-Http-Server

5.0.2 版本中咱们还强化了 PHP 的内置 Web 服务器,更新内容包含:

  • 通过 -W <过程数量> 启动多个工作过程
  • 增加了过程管理器,工作过程异样退出后,能够从新拉起新的过程
  • 通过 -o <log_file> 设置申请日志文件的门路
  • 在申请日志中增加了解决耗时信息
  • 写日志时应用 flock 加锁,避免多过程写日志可能呈现的错乱
  • 去掉了 select,间接应用 accept 零碎调用,防止启动大量工作过程产生惊群效应节约系统资源
  • 保留应用 -d cli_server.color=on ini 参数设置日志色彩
  • 保留应用 PHP_CLI_SERVER_WORKERS=N swoole-cli -S 环境变量设置工作过程数量
  • 新增应用 -d cli_server.log_level=0 ini 参数设置日志等级
htf@htf-ThinkPad-T470p:~/workspace$ swoole-cli -hUsage: swoole-cli [options] [-f] <file> [--] [args...]   swoole-cli [options] -r <code> [--] [args...]   swoole-cli [options] [-B <begin_code>] -R <code> [-E <end_code>] [--] [args...]   swoole-cli [options] [-B <begin_code>] -F <file> [-E <end_code>] [--] [args...]   swoole-cli [options] -P --fpm-config <file>   swoole-cli [options] -S <addr>:<port> [-t docroot] [router]   swoole-cli [options] -- [args...]   swoole-cli [options] -a  -a               Run as interactive shell (requires readline extension)  -P               Run with fpm  -S <addr>:<port> Run with built-in web server.  -c <path>|<file> Look for php.ini file in this directory  -n               No configuration (ini) files will be used  -d foo[=bar]     Define INI entry foo with value 'bar'  -e               Generate extended information for debugger/profiler  -f <file>        Parse and execute <file>.  -h               This help  -i               PHP information  -l               Syntax check only (lint)  -m               Show compiled in modules  -r <code>        Run PHP <code> without using script tags <?..?>  -B <begin_code>  Run PHP <begin_code> before processing input lines  -R <code>        Run PHP <code> for every input line  -F <file>        Parse and execute <file> for every input line  -E <end_code>    Run PHP <end_code> after processing all input lines  -H               Hide any passed arguments from external tools.  -U               Update swoole-cli to the latest version  -t <docroot>     Specify document root <docroot> for built-in web server.  -W <worker_num>  Specify number of workers <worker_num> for built-in web server.  -o <log_file>    Specify log file path <log_file> for built-in web server.  -s               Output HTML syntax highlighted source.  -v               Version number  -w               Output source with stripped comments and whitespace.  -z <file>        Load Zend extension <file>.  args...          Arguments passed to script. Use -- args when first argument                   starts with - or script is read from stdin  --ini            Show configuration file names  --rf <name>      Show information about function <name>.  --rc <name>      Show information about class <name>.  --re <name>      Show information about extension <name>.  --rz <name>      Show information about Zend extension <name>.  --ri <name>      Show configuration for extension <name>.

减少 readline 扩大

新增了 readline 扩大,在应用 swoole-cli -a 交互式终端时,取得主动补全的能力。