Swoole-Cli v5.0.2 增加 opcache/readline 扩展,强化 Cli-Server

韩天峰韩天峰 -
Swoole-Cli v5.0.2 增加 opcache/readline 扩展,强化 Cli-Server

最近我们发布了 Swoole-Cli v5.0.2,这个版本增加了 opcache 扩展,使得 swoole-cli 内置的 php-fpmcli-http-server 也可以用于生产环境了,而不仅仅是作为测试使用。

目前 swoole-cli 支持了 5 种环境的二进制包可供大家选择:

Linux x86-64Linux arm64aarch64Windows CygWin x86-64macOS arm64aarch64Apple M1/M2macOS x86-64下载地址:https://www.swoole.com/download

Swoole-Cli 是完全静态编译的,不依赖任何动态链接库,可直接下载到任意操作系统上使用,而不需要额外其他第三方包。

Docker/K8s 环境下也尤为便利,可使用最简化的 alpine linux 基础镜像,然后安装 swoole-cli 构建镜像,最终的镜像只有 100M-200M

增加 Opcache 扩展
swoole-cli --ri opcache

opcache

Version => 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 -h
Usage: 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 交互式终端时,获得自动补全的能力。

特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。

php介绍

PHP即“超文本预处理器”,是一种通用开源脚本语言。PHP是在服务器端执行的脚本语言,与C语言类似,是常用的网站编程语言。PHP独特的语法混合了C、Java、Perl以及 PHP 自创的语法。利于学习,使用广泛,主要适用于Web开发领域。

Tags 标签

phpswoole

扩展阅读

加个好友,技术交流

1628738909466805.jpg