What is PHP ob_implicit_flush() Function?
If you want to send (flush) every output statement (ex. echo, print) immediately to the browser, call ob_implicit_flush() function. You can implicitly enable or disable flush with this function.
Syntax:
ob_implicit_flush($enable)
Parameters:
The function has one parameter.
$enable– it has 2 values-
- When its value is 1 (TRUE), implicit flushing is turned on. If you don’t mention this parameter, the function turns implicit flushing on.
- When it is 0 (FALSE), implicit flushing is turned off.
Return Values:
The function doesn’t return any value.
Examples:
Example 1:
<?php
ob_implicit_flush(1);
echo str_pad("Wait 1 sec... ",4096);
sleep(1);
echo "Done";
?>
Output:
Wait 1 sec... Done
Explanation:
As the implicit flush is turned on in line #2, the string “Wait 1 sec… ” which is produced in line #3 goes immediately to the browser when the browser loads. Then, after waiting for 1 second (line #4), the script prints “Done” (line #5).
Example 2:
<?php
ob_implicit_flush(0);
echo str_pad("Wait 1 sec... ",4096);
sleep(1);
echo "Done";
?>
Output:
Wait 1 sec... Done
Explanation:
As the implicit flush is turned off in line #2, the string “Wait 1 sec… ” which is produced in line #3 doesn’t go immediately to the browser when the browser loads. Then, after waiting for 1 second (line #4), the script prints “Wait 1 sec… Done” (line #5) at a time.
PHP Version Support:
PHP 4, PHP 5, PHP 7, PHP 8
Summary: PHP ob_implicit_flush() Function
PHP ob_implicit_flush() function is a built-in PHP function and part of the PHP’s Output Control functions. With this function, you have control over flushing out each output operation.
Reference:
https://www.php.net/manual/en/function.ob-implicit-flush.php