0

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.

2
  • You could use pthreads, it's a PHP extension which allow you to use threads, The requests would still queued up, but it would only take the thread to start before the next Queued item would execute, and it will not wait until the file_get_contents() function finishes Commented Mar 19, 2017 at 12:41
  • Please don't use pthreads for this, there's an answer that's correct, using pthreads in this instance is the worst thing imaginable. Commented Mar 19, 2017 at 18:09

1 Answer 1

2

Use Guzzle lib or curl_multi_exe

Guzzle is OOP-style library - more effictivily and your tests

Curl simple and quick way to achieve the desired behavior.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.