Jump to content

echo 'while' cURL is doing it's thing.


soma56

Recommended Posts

Is anyone familiar echoing text while cURL procesing? It takes a few seconds and would be nice to echo something out to the user to let them know the status.

 

I've tried different things like...

 

<?PHP
echo "Please Wait..";
sleep(5);

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL, $url);
curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1);
curl_setopt($curl_handle, CURLOPT_TIMEOUT, 150);
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);

?>

 

...and other variations however the page seems to want to load everything - at once. What I'd like to happen is for the text to echo first and/or prior/while cURL is doing its thing.

Link to comment
https://forums.phpfreaks.com/topic/205126-echo-while-curl-is-doing-its-thing/
Share on other sites

After doing more research I discovered that one way around this would be to "flush the buffer" or (according to php.net) "This attempts to push current output all the way to the browser with a few caveats. " As a result, this worked effectively to solve my problem:

<?PHP
echo "Please Wait.." . "<br />". PHP_EOL;
        	ob_flush();
		flush();
        	usleep(50000);
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.