2

I need to flush the content before the page loads, but I can't add additional characters because what I need to print is a JSON encoded array. I have PHP 7.2 and nginx.

I read this and I tried almost all answers but my script only flushes if I reach the minimum size. I configured my php.ini and nginx.conf as the marked as working question says.

What I mean if that if I use the following code, it works.

ob_implicit_flush(1);

for($i=0; $i<10; $i++){
    echo $i;

    echo str_repeat(' ', 1024*64); #This is to reach the minimum buffer size in order to flush

    sleep(1);
}

But if I remove the str_repeat and I just print a JSON encoded array that doesn't reach the minimum size to flush the data I still need to wait for the page to load.

I need to be able to flush whenever I want, without that limit.

Neneone
  • 57
  • 6
  • FWIW: [continue processing php after sending http response](https://stackoverflow.com/questions/15273570/continue-processing-php-after-sending-http-response) I would use the other `ob_` functions. I've never once used `ob_implicit_flush`. – ficuscr Jul 25 '19 at 17:49
  • @ficuscr I'm sorry but it doesn't work: I tried the codes that people suggested in the answers section of that post but them didn't work. I still need to wait for the background process to finish to display `$result` – Neneone Jul 25 '19 at 20:32
  • Note: `echo str_repeat(' ', 4096);` seems to be sufficient. https://www.php.net/manual/en/function.flush.php#51679 – Avatar Feb 18 '22 at 09:32

0 Answers0