Sunday, 19 March 2017

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. 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:

$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. 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? Thanks for any help.



via Nedas

No comments:

Post a Comment