首页 > 解决方案 > Display echo on the screen while executing PHP code

问题描述

I have the code below in PHP. I would like him to display echo while running PHP. But it only displays after the while ends. That is, after php finishes running

The intention is to show progress throughout the execution. I wanted the echo to be displayed at the end of each loop

   <?php

$id_estado = 0;

while ($id_estado<5) {

      echo "OK";
      $id_estado++;
      sleep(2);

}

标签: php

解决方案


You will need to set up the output for buffering. Try to place the code before your while loop.

ob_implicit_flush(true);
ob_end_flush();

推荐阅读