0
function xyz() {
    $url = "http://example.com";
    return $this->getdata($url);
}

function abc() {
    $url = "http://example.org";
    return $this->getdata($url);
}

  function getdata($url) {
      $curl = curl_init($url);
      curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
      $output = curl_exec($curl);
      curl_close($curl);
      return $output;
  }

I have a function getdata() to retrieve remote webpages and two functions abc() and xyz() with two unique url that are to be retrieved.

Now the problem is that each request for getdata() takes around 5 seconds, I have many functions like abc() and xyz(), so calling them sequentially will cost me a lot of time.

Is there any way to call these functions simultaneously? Send multiple requests together? So no matter how many requests there are, they will always take aroung 5 seconds?

Kazi Lotus
  • 172
  • 2
  • 9
  • No none of this is for DOS attack, I have a root server :| To be precise I want to request from 5 url only at once. – Kazi Lotus Aug 05 '15 at 16:38
  • Why am I getting downvoted ? – Kazi Lotus Aug 05 '15 at 16:44
  • A similar question could be posed without http requests that's completely useful. If you have 5 arrays that you want to do a custom sort function on that takes 3 seconds each. How could you sort them all at the same time so that the process only takes 3 seconds instead of 15. – Andrew Jul 27 '17 at 15:07

1 Answers1

0

A workaround could be using curl's multiple parallel requests, as described in the next answer:

https://stackoverflow.com/a/9311112/5194892

Community
  • 1
  • 1