Swoole-Cli 介绍

Swoole-Cli 是一个 PHP 的二进制发行版,集成了 swoolephp 内核php-cliphp-fpm以及多个罕用扩大。Swoole-Cli 是全副动态编译打包的,不依赖任何操作系统的so动态链接库,具备十分好的移植性,能够在任意 Linux 零碎之间复制,下载即可应用。

GitHub: https://github.com/swoole/swoole-cli

操作系统

Swoole-Cli 会提供LinuxmacOSWindows(Cygwin) 3种操作系统的二进制包的反对。

Windows 环境举荐应用 WSL

次要更新

  1. PHP 同步到 8.1.12 版本
  2. 减少了 mongodb 扩大
  3. 集成了 cli http serverphp-fpm

下载安装

下载地址:

  • linux x64:https://wenda-1252906962.file.myqcloud.com/dist/swoole-cli-v5.0.1-linux-x64.tar.xz

间接下载后搁置到 /usr/bin 目录,并且设置为可运行,chmod +x /usr/bin/swoole-cli 即可。在终端中执行:

swoole-cli -vswoole-cli -m

代替 PHP

Swoole-Cli 软链接到 php,代替 PHP

ln -s /usr/bin/swoole-cli /usr/bin/phpphp -v# 装置 composercurl -sS https://getcomposer.org/installer | php

配置文件

swoole-cli 默认不加载任何 php.ini 配置文件。

可通过 -d 参数来设置 PHP 选项或应用 -c 参数指定加载的php.ini配置文件。

swoole-cli -d swoole.use_shortname=off bin/hyperf.php startswoole-cli -c /tmp/php.ini -v

启动 PHP-FPM

swoole-cli 集成了 PHP-FPM ,可应用 -P 命令来启动 fpm

# 查看帮助文件swoole-cli -P -h# 运行 FPMswoole-cli -P --fpm-config /opt/php-8.1/etc/php-fpm.conf -p /opt/php-8.1/var# 敞开守护过程swoole-cli -P --fpm-config /opt/php-8.1/etc/php-fpm.conf -p /opt/php-8.1/var -F# 应用 root 账户启动swoole-cli -P --fpm-config /opt/php-8.1/etc/php-fpm.conf -p /opt/php-8.1/var -F -R

启动 CLI Server

# 应用 Laravel Artisan 工具swoole-cli artisan serve# 启动 CLI Serverswoole-cli -S 127.0.0.1:9001

启动 Swoole Server

server.php

$http = new Swoole\Http\Server('127.0.0.1', 9501);$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');});$http->start();

执行

swoole-cli server.php

扩大列表

[email protected]:~/workspace/cli-swoole$ ./bin/swoole-cli -m[PHP Modules]bcmathbz2CorectypecurldatedomexiffileinfofiltergdgmphashiconvimagickintljsonlibxmlmbstringmongodbmysqlimysqlndopensslpcntlpcrePDOpdo_mysqlpdo_sqlitePharposixredisReflectionsessionSimpleXMLsoapsocketssodiumSPLsqlite3standardswooletokenizerxmlxmlreaderxmlwriterxslyamlzipzlib[Zend Modules]