-3

I am trying to show another page loop using CURL but its not show data at real time after loop finish output will show. I need this real time. check this example code. and if there is another way to do this please tell me. I don't want to show my loop page URL so i use Curl to do that if any other way you know please tell.

Output Page

$ch = curl_init('http://localhost/test/loop.php');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
echo $hasil = curl_exec ($ch);
curl_close ($ch);
?>

Loop page

 <?php
     $a = 1;
     while (true) {
         echo $a;
         $a++;
         sleep(1);
     }
?>
iehrlich
  • 3,572
  • 4
  • 34
  • 43
hizo
  • 1
  • 1

1 Answers1

0

You can do this using output buffering.

$a = 1;
while(true){
    ob_start();
    echo $a;
    $a++;
    ob_flush();
    sleep(1);
}

You will need to configure php to allow for this if you have not done so already. There are settings in the PHP ini for it. This answer will explain how to do this PHP echo-ing content as page loads

It is worth noting that the code above will cause a php timeout based on whatever you have set in the php.ini

Dan Hastings
  • 3,241
  • 7
  • 34
  • 71
  • you may need to configure php to do this. https://stackoverflow.com/questions/6396630/php-echo-ing-content-as-page-loads – Dan Hastings Jul 06 '17 at 09:17