• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Question ob_flush(); is not working

mfarooqi

New Pleskian
Hello,
I have been trying to make following code work.


PHP:
ob_flush();
flush();

following code works perfectly fine on my local host with PHP7x.

PHP:
header('Content-Type: text/html; charset=UTF-8');
if (ob_get_level() == 0) ob_start();
for ($i = 0; $i < 10; $i++) {
    echo '|'.$i;
    ob_flush();
    flush();
    usleep(1000000); // 1s
}

on my localhost it appends one number and shows on screen every second.
but this is not working on Plesk server with PHP7x and PHP8x

I've added following lines in PHP Settings for my domain

output_buffering = on

But flush() is not working.

I'm the root user (administrator) of my VPS.. I can access to PHP.INI.. I can make changes into that too. But doesn't seem it is working. Whenever I hit the URL .. it holds for 10seconds and then shows the out put all at once.

Can somebody please suggest me what things should I make to make it work.
 
I can only say that the issue is broadly discussed and can have many reasons including client behavior. The correct solution here would be to waive server-side updates and do the same thing client-driven, e.g. by AJAX. Please see threads like How to flush output after each `echo` call? where a very similar issue has been discussed.
 
I am actually using a number of "mixed" AJAX and PHP functions. I can handle Ajax calls. But in this particular scenario There are a number of PHP based processings. And I want to know which function is currently running to show user "actual" processing in the backend.
 
OK, but did you check the Stack Overflow thread that Peter provided? There's one post that said it worked for him once he confirmed gzip is off along with any other compressions. Your local test server probably has it all off as it usually is by default but by default Plesk usually have compressions enable to allow for faster speeds.
 
Hmmm okay. Turning off Gzip will be permanent? Can we do this change on and off before running the script and after running the script respectively? Also is it a domain based setting or server based? I have a VPS. I can make a new subdomain based an a separate account with this setting if this is domain based.
I don’t want to effect the speed otherwise!

Well this all still depends if flush would work. Let me try this today first.
Thank you.
 
The settings is per domain and can be edited under domains > domain (or subdomain) > hosting & dns > apache & nginx settings
 
Back
Top