IE盒子

搜索
查看: 116|回复: 3

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

[复制链接]

2

主题

5

帖子

9

积分

新手上路

Rank: 1

积分
9
发表于 2023-3-25 19:47:30 | 显示全部楼层 |阅读模式
最近我们发布了 Swoole-Cli v5.0.2,这个版本增加了 opcache 扩展,使得 swoole-cli 内置的 php-fpm、cli-http-server 也可以用于生产环境了,而不仅仅是作为测试使用。
目前 swoole-cli 支持了 5 种环境的二进制包可供大家选择:

  • Linux x86-64
  • Linux arm64 (aarch64)
  • Windows CygWin x86-64
  • macOS arm64 (aarch64、Apple M1/M2)
  • macOS 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-fpm、cli-http-server ,但由于未支持 opcache 扩展,所以仅可用于测试环境。新的 5.0.2 版本中将 opcache 也静态编译到了 swoole-cli 二进制程序中。
这样内置的 php-fpm、cli-http-server 服务就可以使用 opcache 和 opcache.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 交互式终端时,获得自动补全的能力。

回复

使用道具 举报

3

主题

4

帖子

9

积分

新手上路

Rank: 1

积分
9
发表于 2023-3-25 19:48:03 | 显示全部楼层
请不要为了兼容而兼容,大家需要的是一个快速 可用 php语法 就可以了。
既然已经选择了swoole_cli这条路,如果swoole cli已经足够快速了,还要兼容opcache、php server cli这些做什么呢?不仅繁琐混乱、还添加了心智负担,到底该用哪个?   
谢谢大佬!
回复

使用道具 举报

1

主题

4

帖子

6

积分

新手上路

Rank: 1

积分
6
发表于 2023-3-25 19:48:19 | 显示全部楼层
php生态是绕不过”兼容“这个话题。swoole生态能尽可能兼容是个好事。
回复

使用道具 举报

2

主题

8

帖子

12

积分

新手上路

Rank: 1

积分
12
发表于 2023-3-25 19:48:29 | 显示全部楼层
如果不兼容,长远来说肯定要分道扬镳,否则就要融入,未来的方向肯定是只能选择一个,否则若即若离,Swoole生态不好搞
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表