n14charlie Posted May 21, 2009 Share Posted May 21, 2009 Hey I need help using the PHP flush function. I'm making a one time call to a php script and I want it to keep outputing stuff back to the client before it ends (inside a loop) I tried using the flush function but it doesn't work.. can anyone tell me how do I do that? thank you Link to comment https://forums.phpfreaks.com/topic/159095-php-flush/ Share on other sites More sharing options...
thebadbad Posted May 21, 2009 Share Posted May 21, 2009 <?php ob_start(); for ($i = 1; $i <= 10; $i++) { sleep(1); echo "$i<br />"; ob_flush(); flush(); } ?> This works for me in Firefox 3.0.10 and IE8, but it depends on the server settings (and browser). Link to comment https://forums.phpfreaks.com/topic/159095-php-flush/#findComment-838990 Share on other sites More sharing options...
n14charlie Posted May 21, 2009 Author Share Posted May 21, 2009 thanks for response can you tell me what settings of the server should be set in order for it to work? Link to comment https://forums.phpfreaks.com/topic/159095-php-flush/#findComment-838995 Share on other sites More sharing options...
thebadbad Posted May 21, 2009 Share Posted May 21, 2009 Have a read at http://dk2.php.net/manual/en/function.flush.php Link to comment https://forums.phpfreaks.com/topic/159095-php-flush/#findComment-838997 Share on other sites More sharing options...
MasterACE14 Posted May 21, 2009 Share Posted May 21, 2009 <?php ob_start(); for ($i = 1; $i <= 10; $i++) { sleep(1); echo "$i<br />"; ob_flush(); flush(); } ?> This works for me in Firefox 3.0.10 and IE8, but it depends on the server settings (and browser). yeah I just tested that script in Opera and doesn't work lol. Probably not Opera though, server settings I'm assuming like you said. Link to comment https://forums.phpfreaks.com/topic/159095-php-flush/#findComment-839002 Share on other sites More sharing options...
PFMaBiSmAd Posted May 21, 2009 Share Posted May 21, 2009 All of the web server, php, and browser compression, buffering, and minimum length block settings must must be satisfied, bypassed (flushed), or disabled. If you are only going to be using this for yourself on your server, you have a chance of making it work. If you expect this to work once it is out of your hands, forget attempting to write an application this way, it is not how web servers and browsers were designed to work. Link to comment https://forums.phpfreaks.com/topic/159095-php-flush/#findComment-839004 Share on other sites More sharing options...
n14charlie Posted May 21, 2009 Author Share Posted May 21, 2009 Well the thing is I'm writing an ajax application and I need it to check for online update every second, so my only other option is keep calling that PHP script again and again .. so what would you guys recommend? Link to comment https://forums.phpfreaks.com/topic/159095-php-flush/#findComment-839012 Share on other sites More sharing options...
MasterACE14 Posted May 21, 2009 Share Posted May 21, 2009 every second may be abit demanding on the server if there is alot of users on it at the sametime. Link to comment https://forums.phpfreaks.com/topic/159095-php-flush/#findComment-839016 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.