Parallel HTTP requests in PHP using PECL HTTP classes [Answer: HttpRequestPool class]

前端 未结 6 2223
生来不讨喜
生来不讨喜 2020-12-14 22:57

The HttpRequestPool class provides a solution. Many thanks to those who pointed this out.

A brief tutorial can be found at: http://www.phptutorial.i

6条回答
  •  醉话见心
    2020-12-14 23:59

    I'm pretty sure HttpRequestPool is what you're looking for.

    To elaborate a little, you can use forking to achieve what you're looking for, but that seems unnecessarily complex and not very useful in a HTML context. While I haven't tested, this code should be it:

    // let $requests be an array of requests to send
    $pool = new HttpRequestPool();
    foreach ($requests as $request) {
      $pool->attach($request);
    }
    $pool->send();
    foreach ($pool as $request) {
      // do stuff
    }
    

提交回复
热议问题