forrest79/phpfpm-request
Composer 安装命令:
composer require forrest79/phpfpm-request
包简介
Run php-fpm requests from command line.
README 文档
README
Simply utility to make php-fpm requests right from command line with no needs to set up your web server for these requests.
Installation
The recommended way to install Forrest79/PhpFpmRequest is through Composer:
composer require forrest79/phpfpm-request
This also needs cgi-fcgi installed on your system. On Debian (Ubuntu...) like linux, you can do this:
sudo apt install libfcgi0ldbl
You can you this to clear some caches from cli that need to be called via HTTP request (opcache, apcu, ...) or to warm up your cache after a new version is deployed and before web server is started to point to new source code.
How to use it
We just need to know, where is php-fpm listening. It's config directive listen and it could be socket or TCP\IP.
In nginx it's directive fastcgi_pass. If you don't know that, or you're planning to run this on different systems, you can try to autodetect this:
$requester = Forrest79\PhpFpmRequest\Requester::autodetect();
Or if you know where php-fpm is listening, you can use this value:
$requester = Forrest79\PhpFpmRequest\Requester::create('/var/run/php/php7.4-fpm.sock');
Now just simple set PHP file to process with php-fpm:
$requester->setPhpFile('/var/www/index.php');
And send the request:
$response = $requester->send();
Now we have Response object, that can return array of HTTP headers and text body.
echo $reponse->getBody() . PHP_EOL; foreach ($response->getHeaders() as $header) { echo $header . PHP_EOL; }
If you need to pass more options to php-fpm, just use setOption(string $name, string $value) method. Only REQUEST_METHOD is set automatically to GET and SCRIPT_FILENAME is pass. But you can add anything you want:
$requester ->setOption('QUERY_STRING', '?param=1') ->setOption('SERVER_NAME', 'my-server.com') ->setOption('REQUEST_URI', '/show-detail/');
If you need better API for this, extends Requester with your own class and create better public API and in every method just call parent::setOption('...', '...').
Cli and php-fpm in one file
You can have cli and php-fpm source code in one file:
if (PHP_SAPI === 'cli') { echo Forrest79\PhpFpmRequest\Requester::autodetect() ->setPhpFile(__FILE__) ->send() ->getBody() . PHP_EOL; } else { echo 'This code is processed with php-fpm. You can warm up your cache here, clean cache, etc.'; }
forrest79/phpfpm-request 适用场景与选型建议
forrest79/phpfpm-request 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.66k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2018 年 11 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「cli」 「request」 「phpfpm」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 forrest79/phpfpm-request 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 forrest79/phpfpm-request 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 forrest79/phpfpm-request 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
HTTP request logger middleware for Laravel
Adds request-parameter validation to the SLIM 3.x PHP framework
Slim starter / Slim skeleton package to boost your development with Slim framework
A simple HTTP application builder using PSR-15 HTTP Server Request Handler and Middleware.
Generates a trait to help ease the access of custom repo methods
Marussia request
统计信息
- 总下载量: 1.66k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2018-11-11