title: Multiple function calls asynchronously in PHP
body: <p>I'm using Symfony 3 and <a href="https://reactphp.org/" rel="nofollow noreferrer">ReactPHP</a> library for control all my functionality and I need to execute multiple calls to same function (<code>subFunction()</code> in code) <strong>asynchronously</strong>.
  I have 2 projects (project1 and project2):</p>
  
  <p><strong>Project 1</strong> code:</p>
  
  <pre><code>/**
  * Loop an array of urls and call sub function.
  **/
  public function startFunction() {
    $finalResponse = [];
    $urls = ['www.google.es', 'www.github.com', 'www.bitbucket.org'];
  
    foreach ($urls as $url) {
      $res = $this-&gt;subFunction($url);    // subfunction call ( **IT MAY TAKE A LONG TIME !!** )
      $finalResponse[] = $res;
   }
  
   return $finalResponse;
  }
  
  /**
  * Uses Factory loop to get the Promise returned by finalRequest function.
  **/
  private function subFunction($url) {
    $loop = \React\EventLoop\Factory::create();
    $classA = new Project2\ClassA();
    $finalResponse = null;
  
    // project 2 function call
    $classA-&gt;finalRequest($url)-&gt;then(function($response) use(   
       &amp;$finalResponse
    ) {
       $finalResponse = $response;
    })
  
    return $finalResponse;
  }
  </code></pre>
  
  <p><strong>Project 2</strong> code:</p>
  
  <pre><code>classA {
  
  /**
  * Makes an React\HttpClient request (GET) to sent url and return his value inside a Promise.
  **/
  public function finalRequest($url) {
     $generalDeferred = new Deferred();
     $generalPromise = $generalDeferred-&gt;promise();
  
     // make React\HttpClient request
     $request = $client-&gt;request('GET', $url);
     $request-&gt;on('response', function ($response) use($generalDeferred) {
     $response-&gt;on('data', function ($response) {
          $generalDeferred-&gt;resolve($response);
        });
     });
    $request-&gt;end();
  
    return $generalPromise;
  }
  
  }
  </code></pre>
  
  <p>Problem is that on every <code>subFunction($url)</code> call, the program stops until the sub Function gets the response, but I need to do this asynchronously because this subFunction could take many seconds.
  So I would like to launch all <code>subFunction($url)</code> calls at the same time, and get all responses asynchronously.</p>
  
  <p>It's possible solve this problem? Thanks.</p>