ballhogjoni Posted September 6, 2011 Share Posted September 6, 2011 I have looked at ob_start, ob_get_contents, etc.. but I can't get it to work. My code looks like this: ob_start(); echo "starting"; ob_flush(); //do some stuff echo "something else" ob_flush(); //do some stuff echo "something else" ob_flush(); The echoes are only shown at the end of the script execution. Quote Link to comment https://forums.phpfreaks.com/topic/246561-how-do-you-echoflush-strings-during-script-execution/ Share on other sites More sharing options...
requinix Posted September 6, 2011 Share Posted September 6, 2011 It's ultimately up to the browser as to whether it shows the text as the page is downloading or not - IE hasn't always done so but the others typically do. Remember to use sleep() so you actually have time to watch, and double-check that you don't have any kind of output buffering enabled by default (which it generally isn't). echo "First echo "; flush(); sleep(10); echo "Second echo"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/246561-how-do-you-echoflush-strings-during-script-execution/#findComment-1266068 Share on other sites More sharing options...
ballhogjoni Posted September 6, 2011 Author Share Posted September 6, 2011 requinix, that doesn't work for me, i tried it in chrome and ff 5 Quote Link to comment https://forums.phpfreaks.com/topic/246561-how-do-you-echoflush-strings-during-script-execution/#findComment-1266084 Share on other sites More sharing options...
requinix Posted September 6, 2011 Share Posted September 6, 2011 Are you on Windows? Quote Link to comment https://forums.phpfreaks.com/topic/246561-how-do-you-echoflush-strings-during-script-execution/#findComment-1266088 Share on other sites More sharing options...
premiso Posted September 6, 2011 Share Posted September 6, 2011 that doesn't work for me, i tried it in chrome and ff 5 I think the better question is, what is your ultimate goal with this process? Browsers choose not to display output buffer on their own and hold it to the end in an attempt to cache. Chrome is crazy with caching, I have not worked with FF5 much but I am sure it is heading that way as well. If you let us know what your goal is, I think we will be able to help more. Quote Link to comment https://forums.phpfreaks.com/topic/246561-how-do-you-echoflush-strings-during-script-execution/#findComment-1266089 Share on other sites More sharing options...
ballhogjoni Posted September 6, 2011 Author Share Posted September 6, 2011 that doesn't work for me, i tried it in chrome and ff 5 I think the better question is, what is your ultimate goal with this process? Browsers choose not to display output buffer on their own and hold it to the end in an attempt to cache. Chrome is crazy with caching, I have not worked with FF5 much but I am sure it is heading that way as well. If you let us know what your goal is, I think we will be able to help more. I am on mac osx and my goal is to display to the user (my self) where I'm at within the script. My script runs for about 10 seconds do many things IE installing file, unzipping them, creating mysql tables, adding data to those tables, etc... I would like to see that the script is uploading a file, then when it unzips it, I would like to see that. I would like to see when the script install the tables and then see when it adds data to the tables. I hope that made sense. Quote Link to comment https://forums.phpfreaks.com/topic/246561-how-do-you-echoflush-strings-during-script-execution/#findComment-1266093 Share on other sites More sharing options...
premiso Posted September 6, 2011 Share Posted September 6, 2011 Output buffer is not ideal for that job, unfortunately. Since some browsers choose to ignore it and hold all output to the end. What I would look into is using an AJAX type script to report you the status of how it is going, sort of like a "processing" script. That way you just keep the feed open and update the data on the page with ajax. Quote Link to comment https://forums.phpfreaks.com/topic/246561-how-do-you-echoflush-strings-during-script-execution/#findComment-1266095 Share on other sites More sharing options...
Cineex Posted September 6, 2011 Share Posted September 6, 2011 If you have access to it use CLI (Command line interface) it will always output what you echo/print and it won't wait for a buffer. Just remember to use "\r\n" insted of "<br>". on linux/mac: open terminal write: "php script.php" on windows... i hate windows at thease instances but if you need help with it just ask and i will try and help you. Quote Link to comment https://forums.phpfreaks.com/topic/246561-how-do-you-echoflush-strings-during-script-execution/#findComment-1266223 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.