PHP concurrent HTTP requests?

I was wondering what is the best way to execute concurrent HTTP requests in PHP? I have a lot of data, and I would prefer to make several queries at once to get all this.

Does anyone know how I can do this? Preferably in the anonymous / callback function mannor ...

Thank,

Tom.

+3
source share
4 answers

You can use curl_multi , which internally runs several separate requests under one curl handle.

PHP // "" , - ( , script, exec(), ..).

+9

, , json. php . ,

xhttp.open("GET", "gotoChatRoomorNot.php?q=[{"+str+"},{"+user1+"},{"+user2"}]", true);

php , : JSON PHP?

So make a line in json format and send it all via http. I think you can perform the same behavior with xml, but I don't know xml

+1
source

you can use HttpRequestPool http://www.php.net/manual/de/httprequestpool.construct.php

$multiRequests = array(
  new HttpRequest('http://www.google.com', HttpRequest::METH_GET),
  new HttpRequest('http://www.yahoo.com', HttpRequest::METH_GET)
  new HttpRequest('http://www.bing.com', HttpRequest::METH_GET)
);

$pool = new HttpRequestPool();
foreach ($multiRequests as $request)
{
  $pool->attach($request);
}

$pool->send();

foreach($pool as $request) 
{
  echo $request->getResponseBody();
}
0
source

Source: https://habr.com/ru/post/1548738/


All Articles