0

I have a centOS 8 server with Apache FPM/FastCGI as webserver. I want the output to be seen right after each echo. I tried setting output_buffering = Off in php.ini and used below code:

ob_implicit_flush();
ob_start();
echo '1';
ob_end_flush();
@ob_flush();
flush();
sleep(5);
echo '2';

but page remains on loading for 5 seconds and outputs 12 instead of outputting 1 then 2 after 5 seconds.

I used fastcgi_finish_request() to output the whole buffer and do stuff in background and it works correctly.

And also, gzip and deflate are both turned off.

I use above code on my local Windows machine with Apache and also on another server with LiteSpeed and they work without a problem.

Your help is much appreciated!

  • 1
    Did you get this to work? It is really hard to find anything online for a solution on CentOs! – Roemer Dec 17 '22 at 23:01
  • 1
    It's actually webserver related. Ended up writing something like this: public function SendImmediately($Func) { if (php_sapi_name() === 'fpm-fcgi') { echo $Func; fastcgi_finish_request(); } else { ob_start(); echo $Func; header('Connection: close'); header('Content-Length: ' . ob_get_length()); ob_end_flush(); @ob_flush(); flush(); } } – Milad Faint Dec 21 '22 at 09:08

0 Answers0