[英]How to make async requests from PHP to node.js with a response?
I currently have a system like this: 我目前有一个像这样的系统:
An ajax gets sent from a website to .php file, which then sends a request to my node.js server and waits for a response and returns it to the ajax. 一个ajax从网站发送到.php文件,然后将请求发送到我的node.js服务器,等待响应并将其返回给ajax。 I use express to listen for requests: 我用快递来听请求:
app.get('/abc/', function (req, res) {
console.log(req);
});
Currently I use file_get_contents to send a request from PHP: 目前,我使用file_get_contents从PHP发送请求:
$r = file_get_contents("http://".$_SERVER['SERVER_ADDR'].":9991/abc/?secret=123&price=500&token=$token");
This works just fine, however, it's syncronised so multiple ajax requests to this php file get queued up, which I don't want. 这工作得很好,但是,它已同步,因此对该php文件的多个ajax请求被排队,这是我不想要的。 I want them all to execute at the same time, sending requests to my server and waiting for a response. 我希望它们全部同时执行,将请求发送到我的服务器并等待响应。 Is that possible to do with PHP? 这可能与PHP有关吗? Thanks for any help. 谢谢你的帮助。
Use Guzzle lib or curl_multi_exe 使用Guzzle lib或curl_multi_exe
Guzzle is OOP-style library - more effictivily and your tests Guzzle是OOP风格的库-更有效地进行测试
Curl simple and quick way to achieve the desired behavior. 用简单而快速的方法卷曲来实现所需的行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.