我在找到DeferredEventJavaWorker之后做了一些研究,想知道是否可以通过cli / php直接在fpm上运行php脚本。
java和ruby有两个worker实现,最后用一些参数调用fpm,我认为它也应该可以用php,对吗?
这是java worker的代码片段:
FCGIConnection connection = FCGIConnection.open();
connection.connect(new InetSocketAddress(message.getHeader("fastcgi_host"), Integer.parseInt(message.getHeader("fastcgi_port"))));
connection.beginRequest(PathResolver.resolve(message.getHeader("dispatch_path")));
connection.setRequestMethod("POST");
byte[] postData = ("DEFERRED_DATA=" + message.getData()).getBytes();
有一个名为cgi-fcgi
(source)的命令可以将内容发送到fpm:
SCRIPT_NAME=/ping \
SCRIPT_FILENAME=/ping \
REQUEST_METHOD=GET \
cgi-fcgi -bind -connect 127.0.0.1:9000
在php中还有一个库或集成函数吗?
我知道在php中集成了shell函数,但我希望还有另一种方法可以做到这一点。
答案 0 :(得分:1)
最后我找到了php的实现:
https://github.com/ebernhardson/fastcgi/
用法非常简单:
$client = new \EBernhardson\FastCGI\Client('localhost', '8989');
// OR
$client = new \EBernhardson\FastCGI\Client('/var/run/php5-fpm.sock');
$environment = [
'REQUEST_METHOD' => 'GET',
'SCRIPT_FILENAME' => '/full/path/to/script.php',
];
$client->request($environment, '');