asmblah/fast-cgi
Composer 安装命令:
composer create-project asmblah/fast-cgi
包简介
README 文档
README
Simplifies management of a real php-cgi worker process or php-fpm worker pool.
Leverages the excellent hollodotme/fast-cgi-client for a FastCGI API.
Why?
Easy testing of a FastCGI application's behaviour across requests: for example, ensuring that opcache is cleared correctly when expected.
Usage
$ composer install --dev asmblah/fast-cgi
Launching a php-cgi instance and making a GET request to it:
Use PhpCgiLauncher for php-cgi.
test.php
<?php declare(strict_types=1); use Asmblah\FastCgi\FastCgi; use Asmblah\FastCgi\Launcher\PhpCgiLauncher; require_once __DIR__ . '/vendor/autoload.php'; $baseDir = __DIR__; $wwwDir = 'www'; // Relative to $baseDir. $phpCgiBinaryPath = dirname(PHP_BINARY) . '/php-cgi'; $dataDir = $baseDir . '/var/test'; @mkdir($dataDir, 0700, true); $socketPath = $dataDir . '/php-cgi.test.sock'; $fastCgi = new FastCgi( baseDir: $baseDir, wwwDir: $wwwDir, socketPath: $socketPath, launcher: new PhpCgiLauncher($phpCgiBinaryPath) ); $session = $fastCgi->start(); $response = $session->sendGetRequest( 'my_script.php', '/path/to/my-page', [ 'greeting' => 'Hello', ] ); // Will print "Hello from my front controller!". print $response->getBody() . PHP_EOL; $session->quit();
www/my_script.php
<?php declare(strict_types=1); print ($_GET['greeting'] ?? '(none)') . ' from my front controller!';
Run
$ php test.php
Hello from my front controller!
Launching a php-fpm instance and making a GET request to it:
Use PhpFpmLauncher for php-fpm.
test.php
<?php declare(strict_types=1); use Asmblah\FastCgi\FastCgi; use Asmblah\FastCgi\Launcher\PhpFpmLauncher; require_once __DIR__ . '/vendor/autoload.php'; $baseDir = __DIR__; $wwwDir = 'www'; // Relative to $baseDir. $phpFpmBinaryPath = dirname(PHP_BINARY, 2) . '/sbin/php-fpm'; $dataDir = $baseDir . '/var/test'; @mkdir($dataDir, 0700, true); $socketPath = $dataDir . '/php-fpm.test.sock'; $logFilePath = $dataDir . '/php-fpm.log'; $configFilePath = $dataDir . '/php-fpm.conf'; file_put_contents($configFilePath, <<<CONFIG [global] error_log = $logFilePath [www] listen = $socketPath pm = static pm.max_children = 1 CONFIG ); $fastCgi = new FastCgi( baseDir: $baseDir, wwwDir: $wwwDir, socketPath: $socketPath, launcher: new PhpFpmLauncher( $phpFpmBinaryPath, $configFilePath ) ); $session = $fastCgi->start(); $response = $session->sendGetRequest( 'my_script.php', '/path/to/my-page', [ 'greeting' => 'Hello', ] ); // Will print "Hello from my front controller!". print $response->getBody() . PHP_EOL; $session->quit();
www/my_script.php
<?php declare(strict_types=1); print ($_GET['greeting'] ?? '(none)') . ' from my front controller!';
Run
$ php test.php
Hello from my front controller!
See also
asmblah/fast-cgi 适用场景与选型建议
asmblah/fast-cgi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.25k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 03 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 asmblah/fast-cgi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 asmblah/fast-cgi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4.25k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-03-30