title: PHP Curl async response
body: <p>I have a PHP file that invokes another PHP file via curl. I am trying to have the second file send a response back to the first to let it know that it started. The problem is the first can't wait for the first to finish execution because that can take a minute or more, I need it to send a response immediately then go about it's regular business. I tried using an echo at the top of the second file, but the first doesn't get that as a response.
  How do I send back a response without finishing execution?</p>
  
  <p><strong>file1.php</strong></p>
  
  <pre><code>&lt;?php
  $url = 'file2.php';
  $params = array('data'=&gt;$data,'moredata'=&gt;$moredata);
  
  $options = array(
      CURLOPT_RETURNTRANSFER =&gt; true,     // return web page
      CURLOPT_HEADER         =&gt; false,    // don't return headers
      CURLOPT_FOLLOWLOCATION =&gt; true,     // follow redirects
      CURLOPT_ENCODING       =&gt; "",       // handle all encodings
      CURLOPT_USERAGENT      =&gt; "Mozilla", // who am i
      CURLOPT_AUTOREFERER    =&gt; true,     // set referer on redirect
      CURLOPT_CONNECTTIMEOUT =&gt; 120,      // timeout on connect
      CURLOPT_TIMEOUT        =&gt; 120,      // timeout on response
      CURLOPT_MAXREDIRS      =&gt; 10,       // stop after 10 redirects
      CURLOPT_TIMEOUT        =&gt; 10,        // don't wait too long
      CURLOPT_POST           =&gt; true,     // Use Method POST (not GET)
      CURLOPT_POSTFIELDS     =&gt; http_build_query($params)
  );
  $ch = curl_init($url);
  
  curl_setopt_array( $ch, $options );
  $response = curl_exec($ch); // See that the page started.
  curl_close($ch);
  echo  'Response: ' . $response;
  ?&gt;
  </code></pre>
  
  <p><strong>file2.php</strong></p>
  
  <pre><code>&lt;?php
  /* This is the top of the file. */
  echo 'I started.';
  .
  .
  .
  // Other CODE
  .
  .
  .
  ?&gt;
  </code></pre>
  
  <p>When I run file1.php it results in: 'Response: ' but I expect it to be 'Response: I started.' I know that file2.php gets started because 'Other CODE' get executed, but The echo doesn't get sent back to file1.php, why?</p>