Return problem using flush() in php

Asked

Viewed 158 times

0

It’s my first post here on the site. I have a problem that I don’t know how to fix. I don’t know if it’s a limitation of my server...

I would like this code below to return a number after another in the interval of a second, but in my server the page is empty and when it finishes everything comes at once. On the other server works as I want.

echo 'Begin ...<br />';
for( $i = 0 ; $i < 10 ; $i++ )
{
    echo $i . '<br />';
    flush();
    ob_flush();
    sleep(1);
}
echo 'End ...<br />';

I recorded a video explaining the problem.

Youtube


On this server works as I wanted it to be: http://ronaldoguedes.com.br/p3.php

That’s what I need doesn’t work: https://wistats.com.br/main/p3.php

Use NGINX on an instance of the LINODE server with 1GB RAM and 1 core. Is that it? Server limitation?

  • Try it this way: https://answall.com/a/270638/99718

1 answer

1


The probable cause is the NGINX output buffer.

You can, disable the proxy in the configuration file:

proxy_buffering off;

Or try to disable via Reader in your code:

header('X-Accel-Buffering: no');

Reference: http://nginx.org/r/proxy_buffering

  • Thanks Gustavo.... your solution worked!! I managed using the header('X-Accel-Buffering: no'); However I would like to use the above option to stay on all pages. proxy_buffering off; Know which file I should find this line to switch off to?

  • You put it in the file Nginx.conf, just below Location /some/path/ { proxy_buffering off; } probably in /etc/Nginx/Nginx.conf, /usr/local/Nginx/conf/Nginx.conf or /usr/local/etc/Nginx/Nginx.conf

  • Thanks Gustavo... it worked out! Very nice.. was exactly as I wanted... does it have any advantage that I put this code in the instance of the database I have? and in another instance only for cron tasks?

  • Bah, I don’t know... hit my limit. :)

  • without problems.. already helped too much ... thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.