title: What does $loop do in this code sample?
body: <p>Phil Sturgeon wrote this <a href="http://philsturgeon.co.uk/blog/2013/11/benchmarking-codswallop-nodejs-v-php" rel="nofollow">article</a> about benchmarking. </p>
  
  <p>What I am concerned with is this technology called ReactPHP.</p>
  
  <p>I have been to their GitHub, but still cannot wrap my mind around it without an example.</p>
  
  <p>Thankfully, I can use Phil's repo.</p>
  
  <p>At line 12, Phil created a loop with ReactPHP.</p>
  
  <p><a href="https://github.com/philsturgeon/nonblockingbro/blob/master/p2-async.php#L12" rel="nofollow">https://github.com/philsturgeon/nonblockingbro/blob/master/p2-async.php#L12</a></p>
  
  <p>Then he started to use the loop at line 24</p>
  
  <p><a href="https://github.com/philsturgeon/nonblockingbro/blob/master/p2-async.php#L24" rel="nofollow">https://github.com/philsturgeon/nonblockingbro/blob/master/p2-async.php#L24</a></p>
  
  <p>My questions are: </p>
  
  <ul>
  <li>what is the purpose of this <code>$loop</code>? </li>
  <li>It says on the ReactPHP, it is a simple web server. Does that mean it replaces nginx or Apache?</li>
  <li>When is a good time to use ReactPHP or any similar technology? When is NOT a good time to use it?</li>
  </ul>
  
  <p>I am trying to learn about this technology, so if I have worded this question badly, do let me know so I can rewrite this.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Since I am getting feedback that the question is too broad, let me narrow my question and make it refer to a code example.</p>
  
  <p>Taking the code sample from <a href="https://github.com/philsturgeon/nonblockingbro/blob/master/p2-async.php#L12" rel="nofollow">https://github.com/philsturgeon/nonblockingbro/blob/master/p2-async.php#L12</a>,</p>
  
  <p>which I have duplicated below. What does <code>$loop</code> do?</p>
  
  <pre><code>$loop = React\EventLoop\Factory::create();
  
  $dnsResolverFactory = new React\Dns\Resolver\Factory();
  $dnsResolver = $dnsResolverFactory-&gt;createCached('8.8.8.8', $loop);
  
  $factory = new React\HttpClient\Factory();
  $client = $factory-&gt;create($loop, $dnsResolver);
  
  
  echo "Page number, Time taken";
  for ($page = 1; $page &lt;= $total_page; $page++) {
  
      $loop-&gt;addTimer(0.001, function($timer) use ($client, $page) {
          $buffer = '';
          $request = $client-&gt;request('GET', 'http://fantasy.premierleague.com/my-leagues/303/standings/?ls-page='.$page);
          $request-&gt;on('response', function($response) use (&amp;$buffer) {
              $response-&gt;on('data', function($data) use (&amp;$buffer) {
                  $buffer .= $data;
              });
          });
          $request-&gt;on('end', function() use (&amp;$buffer, $page) {
  
              \phpQuery::newDocument($buffer);
  
              foreach (pq('.ismStandingsTable tr') as $data) {
                  foreach (pq('td', $data) as $key =&gt; $val) {
                      if ($key == 2) {
                          // print pq($val)-&gt;text();
                      }
                  }
              }
  
              $time_end = microtime(true);
              $execution_time = $time_end - $GLOBALS['time_start'];
              echo ("\n".$page.", ".$execution_time);
  
          });
          $request-&gt;end();
      });
  }
  
  $loop-&gt;run();
  </code></pre>