根据老大的Merge情况来看,最小的版本可能是 version >= 4.0.40,协议实现请参考:
https://github.com/walkor/workerman/pull/784
<?php
var_dump($_POST, $_GET, date('Y-m-d H:i:s'));
<?php
use Workerman\Worker;
use Workerman\Protocols\FastCGI\Request;
use Workerman\Connection\AsyncTcpConnection;
require_once dirname(__FILE__, 1) . '/workerman/Autoloader.php';
$worker = new Worker();
$worker->name = "FastCGI-Client";
$worker->onWorkerStart = function($worker){
//or use UNIX socket
$connection = new AsyncTcpConnection("unix:///tmp/fpm.sock");
$connection->protocol = "\\Workerman\\Protocols\Fcgi";
//or use TCP socket
$connection = new AsyncTcpConnection("fcgi://127.0.0.1:9000");
$connection->onConnect = function($connection){
$total_request = 100;
for($i = 0; $i < $total_request; $i++)
{
$request = new Request();
$request->setScript("/path/to/script/cgi.php")
->setRequestMethod('post')
->setKeepAlive(true) //default is true
->setQueryString(['k1' => 'v1'])
->setCustomParams(['k2' => 'v2'])
->appendCustomParams(['k3' => 'v3'])
->setContent(['number' => $i+1]);
$connection->send($request);
}
};
//这是暴露给开发者的一个回调,参数 $response 是响应对象
$connection->onResponse = function($connection, $response){
var_dump(
$response->getHeader(),
$response->getBody(),
$response->getStdout(),
$response->getStderr(),
$response->formatOutput()
);
};
$connection->onMessage = function($connection, $data){
var_dump($data)
//打印接收到的响应数据 $data 如下所示
/*Array
(
[requestId] => 99
[status] => 200
[stderr] =>
[header] => Array
(
[X-Powered-By] => PHP/7.4.16
[Content-type] => text/html; charset=UTF-8
)
[body] => 2022-07-15 13:12:04
array(1) {
["number"]=>
string(2) "99"
}
array(1) {
["k1"]=>
string(2) "v1"
}
string(19) "2022-07-15 21:32:04"
)*/
};
$connection->onClose = function($connection){
};
$connection->connect();
};
Worker::runAll();
给你一个大大的赞👍
赞
为什么高级的东西没得多少人点赞
问下, 这个FastCGI 客户端, 可以跨项目使用吗, 处理完请求后, 会释放所有资源吗, 就像传统的php-fpm一样
还是不会释放资源, 同一个项目中可以加速
像我的问题这样
https://www.workerman.net/q/11266