PHP - 按块获取多个URL

My web application needs to parse remote resources from multiple remote servers. The problem is that the output of those remote servers is long / staged. I hence need a piece of code implementing the following logic:

  • Populate array $links_array with a set of links.
  • Some code here....
  • For $i in count($links_array)
    `$results_array[$i] = {what has been output until now without waiting for full response}
  • Some code here....

The answer must not use extensions (except cURL) and work on PHP 5.3.

Thanks a lot for your help.

It seems like you need an asynchronous method of download links. You can look into the Guzzle Library (https://blog.madewithlove.be/post/concurrent-http-requests/). Another option is to use multi curl: http://php.net/manual/en/function.curl-multi-init.php