找到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函数,但是我希望有另一种方法可以做到这一点。
最后,我找到了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, '');
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句