shelluk Posted June 23, 2008 Share Posted June 23, 2008 By what method (is there one built in?) can I display PHP echo's as it goes along. I.E. I have a script running 3 test with 3 results. Test 3 can take say 30 secs to run though. I would like test 1 and 2 results displayed soon as they have finished, without waiting for test 3 results! Test 3 to be echo'd out when that's finished. Hope that makes sense...! Thanks, Shell Quote Link to comment https://forums.phpfreaks.com/topic/111522-displaying-output-as-you-go/ Share on other sites More sharing options...
ober Posted June 23, 2008 Share Posted June 23, 2008 The only way to do this is with something like AJAX. PHP will complete everything in the script before sending it to the client. Quote Link to comment https://forums.phpfreaks.com/topic/111522-displaying-output-as-you-go/#findComment-572578 Share on other sites More sharing options...
shelluk Posted June 23, 2008 Author Share Posted June 23, 2008 Can you give me any links to examples or something related to what I'm trying to do if possible please? Examples I'm finding seem over complicated for what I want and are resulting in me sitting here confused. Thanks, Shell Quote Link to comment https://forums.phpfreaks.com/topic/111522-displaying-output-as-you-go/#findComment-572682 Share on other sites More sharing options...
.josh Posted June 23, 2008 Share Posted June 23, 2008 well it isn't that complicated if you use a clientside language but you're wanting to throw a serverside language into the mix so what do you expect? In a basic ajax tutorial 99% of it is javascript and it's just a couple of functions to set it up and you don't really have to mess with it just c/p it into your file. Quote Link to comment https://forums.phpfreaks.com/topic/111522-displaying-output-as-you-go/#findComment-572688 Share on other sites More sharing options...
mikeschroeder Posted June 23, 2008 Share Posted June 23, 2008 You can definitely do this with just pure php. check out the php flush() function http://us3.php.net/flush for($i=0; $i<1000; $i++){ sleep(2); echo 'Iteration: '.$i.'<br>'; flush(); } just a rough example but it works. Quote Link to comment https://forums.phpfreaks.com/topic/111522-displaying-output-as-you-go/#findComment-572704 Share on other sites More sharing options...
.josh Posted June 23, 2008 Share Posted June 23, 2008 Oh god. I can't believe you're actually seriously suggesting that. Quote Link to comment https://forums.phpfreaks.com/topic/111522-displaying-output-as-you-go/#findComment-572707 Share on other sites More sharing options...
PFMaBiSmAd Posted June 23, 2008 Share Posted June 23, 2008 If you read the description of flush() at that link, you will find all the various conditions where that won't work. In both FF and IE, the posted code does not work for me. Quote Link to comment https://forums.phpfreaks.com/topic/111522-displaying-output-as-you-go/#findComment-572710 Share on other sites More sharing options...
DarkWater Posted June 23, 2008 Share Posted June 23, 2008 Yeah, flush() is hardly ever effective. There's so many different things that can stop it from working properly. =/ Quote Link to comment https://forums.phpfreaks.com/topic/111522-displaying-output-as-you-go/#findComment-572712 Share on other sites More sharing options...
mikeschroeder Posted June 23, 2008 Share Posted June 23, 2008 works on xampp on windows xp as well as a fedora machine as well as both cpanel and direct admin installations on centos all virgin installs all working, although none are running suPHP Quote Link to comment https://forums.phpfreaks.com/topic/111522-displaying-output-as-you-go/#findComment-572718 Share on other sites More sharing options...
DarkWater Posted June 23, 2008 Share Posted June 23, 2008 It doesn't work on many builds. I think that the Suhosin patch is automatically included in PHP6 anyway, lol. Quote Link to comment https://forums.phpfreaks.com/topic/111522-displaying-output-as-you-go/#findComment-572720 Share on other sites More sharing options...
kenrbnsn Posted June 23, 2008 Share Posted June 23, 2008 If you want to go the AJAX route, I suggest you look at the jQuery Javascript library. It really takes all the pain out of AJAX. Ken Quote Link to comment https://forums.phpfreaks.com/topic/111522-displaying-output-as-you-go/#findComment-572723 Share on other sites More sharing options...
shelluk Posted June 24, 2008 Author Share Posted June 24, 2008 Thanks kenrbnsn. Looks good. Will play this evening! Quote Link to comment https://forums.phpfreaks.com/topic/111522-displaying-output-as-you-go/#findComment-573039 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.