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.

3
  • FWIW: continue processing php after sending http response I would use the other ob_ functions. I've never once used ob_implicit_flush. Commented Jul 25, 2019 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 Commented Jul 25, 2019 at 20:32
  • Note: echo str_repeat(' ', 4096); seems to be sufficient. php.net/manual/en/function.flush.php#51679 Commented Feb 18, 2022 at 9:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.