Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Curl output buffer not receiving response
    text
    copied!<p>I have a deal where file1.php curl runs file2.php. file2.php is a long running file, but it sends(or is supposed to send) a response back to file1.php then carry on with it's code. I am using output buffer to try sending this data, but the problem is if I 'return;' right after the flush; file1.php receives the response just fine, but when I try to keep file2.php running, file1.php never receives the response, what I am doing wrong? Is there a different way I must send the response back to file1.php?</p> <pre><code>// file1.php $url = "file2.php" $params = array('compurl'=&gt;$compurl,'validatecode'=&gt;$validatecode); $options = array( CURLOPT_RETURNTRANSFER =&gt; true, // return web page CURLOPT_HEADER =&gt; true, // 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_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); curl_close($ch); echo $response; // file2.php ob_start(); echo 'Running in the background.'; // get the size of the output $size = ob_get_length(); header("HTTP/1.1 200 OK"); // I have tried without this header("Date: " . date('D, j M Y G:i:s e')); // Tried without this header("Server: Apache"); // Tried without this header('Connection: close'); header('Content-Encoding: none'); header("Content-Length: $size"); header("Content-Type: text/html"); // Tried without this // flush all output ob_end_flush(); ob_flush(); flush(); // If I add return; here file1.php gets the response just fine // But I need file2.php to keep processing stuff and if I remove the // return; file1.php never gets a response. </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload