mrbrdo Posted March 15, 2007 Share Posted March 15, 2007 Hey, i'm trying the following: <?php echo "x"; sleep(5); echo "y"; ?> I would expect this to echo x, then after 5 seconds echo y. What it does is echo xy after 5 seconds. I tried many things to disable buffered output, like setting ob_implicit_flush(1);, ob_end_flush(); and even calling flush(); after the echo, but in any case all content gets displayed at one time and not x first, y after 5 seconds. Thank you Link to comment https://forums.phpfreaks.com/topic/42826-no-output-buffering-problem/ Share on other sites More sharing options...
JasonLewis Posted March 15, 2007 Share Posted March 15, 2007 php is server side, so it delays the entire script by however many seconds. thats my understanding anyway. Link to comment https://forums.phpfreaks.com/topic/42826-no-output-buffering-problem/#findComment-207910 Share on other sites More sharing options...
per1os Posted March 15, 2007 Share Posted March 15, 2007 <?php print $x; while (sleep(5) != 0) { //do nothing here } print $y ?> Does that work? Link to comment https://forums.phpfreaks.com/topic/42826-no-output-buffering-problem/#findComment-207997 Share on other sites More sharing options...
boo_lolly Posted March 15, 2007 Share Posted March 15, 2007 aas projectfear said, php is server-side. which means, it will run the entire script, check for errors, then run all the processes in the script, THEN print the output. mrbrdo want's javascript. Link to comment https://forums.phpfreaks.com/topic/42826-no-output-buffering-problem/#findComment-208006 Share on other sites More sharing options...
mrbrdo Posted March 15, 2007 Author Share Posted March 15, 2007 That's not true at all. PERL is server-side too, but it has the capability to do this. Also, what's the point of BUFFERED OUTPUT if not that it buffers the output before actually outputting it.. So if you disable that, you should be getting the page displayed as it's possible. You guys got the terms of server-side scripting mixed up. And no, i don't want javascript, it has nothing to do with what i'm doing. In perl you can do this easily by putitng "$| = 1; " in your script, as stated here: http://www.wellho.net/forum/Perl-Programming/Gradual-output-from-cgi-script.html In PHP disabling buffered output or enabling implicit flush should be doing the same thing, but it's just not working. I appreciate your comments but if you are not familiar with how buffered output works, you might not want to try and help here. You might have noticed UNbuffered output somewhere with chat CGI scripts, where it always says Transferring from www.xxx.com... in your browser... that's basically what i need, i just won't feed the data indefinitely like the chat scripts do, i just want to echo something, process something that takes time, and echo something again. frost110 no, that does not work Thanks Link to comment https://forums.phpfreaks.com/topic/42826-no-output-buffering-problem/#findComment-208023 Share on other sites More sharing options...
Orio Posted March 15, 2007 Share Posted March 15, 2007 This worked for me... <?php ob_start(); echo "x"; ob_end_flush(); sleep(5); echo "y"; ?> Orio. Link to comment https://forums.phpfreaks.com/topic/42826-no-output-buffering-problem/#findComment-208035 Share on other sites More sharing options...
mrbrdo Posted March 15, 2007 Author Share Posted March 15, 2007 Doesn't work for me.. Is it possible there is an Apache module that's doing buffering on it's own? I'm using Apache 2.2.3 on FreeBSD. I can't see any module that could be a problem though, i do have mod_deflate but it's not configured to be enabled for the site where i'm trying this... It could be a server issue though, because when i run on the command line with "php test.php" it works correctly, but when opening it as a web page it does not work correctly (outputs everything at once). Link to comment https://forums.phpfreaks.com/topic/42826-no-output-buffering-problem/#findComment-208046 Share on other sites More sharing options...
mrbrdo Posted March 15, 2007 Author Share Posted March 15, 2007 Wow! This works: <?php echo "x"; ob_flush(); flush(); // Note BOTH need to be used sleep(5); echo "y"; ?> Can anyone explain this? It's confusing me, is there a way to make it work without needing both of these commands after each echo? Link to comment https://forums.phpfreaks.com/topic/42826-no-output-buffering-problem/#findComment-208082 Share on other sites More sharing options...
kenrbnsn Posted March 15, 2007 Share Posted March 15, 2007 This is also dependent on the browser you're using. The following works for me in FF2 but not in MSIE7: <?php echo "x"; flush(); sleep(5); echo "y"; ?> Ken Link to comment https://forums.phpfreaks.com/topic/42826-no-output-buffering-problem/#findComment-208110 Share on other sites More sharing options...
mrbrdo Posted March 17, 2007 Author Share Posted March 17, 2007 it's sounds a bit like a php output buffering bug to me.. i'm talking about needing to call ob_flush() even though ob_end_flush() was called before for example - output buffering should then be disabled.. re Link to comment https://forums.phpfreaks.com/topic/42826-no-output-buffering-problem/#findComment-209429 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.