How to ensure immediate delivery of echo messages to the browser in PHP code


Edit the Apache php.ini file via left clicking the WampServer tray icon, select PHP, then access the PHP by clicking on php [apache module]

Modify the line output_buffering = 4096 to ;output_buffering = 4096 and add output_buffering = Off so in summary the lines will look like:

;output_buffering = 4096

output_buffering = Off

Restart the WampServer services by right clicking the tray icon and selecting Restart from zero


Now add the following code to the start of your PHP script:

ini_set('output_buffering', 'off');

ini_set('implicit_flush', '1');

ob_implicit_flush(1);


Then add the following two commands after the code you want to display:

flush(); ob_flush(); // This tells PHP to send the output from that buffer to the browser


Note! the ob_flush() and flush() commands do work in PHP 8, regardless of whether you're using MySQL or not. These functions are part of PHP's output control system, and they operate independently of the database layer.



Topic last reviewed: 23/07/25