Michdd Posted July 30, 2009 Share Posted July 30, 2009 I noticed that if I'm running something that uses a lot of resources and won't completely finish (Like a really long loop) in a short period of time it will output to the browser, but continue to run and update as it outputs. (Because there's an echo in the loop) But I also noticed I don't get the same effect when this inside of a function. while(something) { echo 'foobar'; } as opposed to: function runWhile() { while(something) { echo 'foobar'; } } The first will output as it goes along, as opposed to the second which won't load the page the same way. Why is this, and is there any way to make the second behave the same as the first? Quote Link to comment Share on other sites More sharing options...
DaiLaughing Posted July 30, 2009 Share Posted July 30, 2009 I don't quite get what you are saying. PHP is executed from start to finish on the Web server. Only then is the complete page sent to your browser. How are you getting it to write to an already displayed page? Quote Link to comment Share on other sites More sharing options...
trq Posted July 30, 2009 Share Posted July 30, 2009 Your php configuration must have implicit_flush enabled for the effect (in your first piece of code) to work. This is notoriously bad on performance within a web server environment. Quote Link to comment Share on other sites More sharing options...
Michdd Posted July 30, 2009 Author Share Posted July 30, 2009 Actually.. I think it's something else.. What I'm doing takes a long time to complete (more than 10 minutes depending on the scale of the current operation). It seems to actually be doing it on both ways. Within the loop the opperation that I'm doing takes between 0.06 and 0.5 seconds. Depending on the method of which I'm doing it, I'm still working out the most efficient way. It seems that when it's working at about 0.06 seconds/loop it displays line and line and kind of looks like a live thing. But when it takes long, like .5seconds /loop it goes and stops. It won't display anything for a few minutes, then it'll display the results from the first couple hundred loops, and a few minutes later it'll display the next couple hundred. Quote Link to comment Share on other sites More sharing options...
trq Posted July 30, 2009 Share Posted July 30, 2009 Is this being executed via a web server or a cli script? Quote Link to comment Share on other sites More sharing options...
Michdd Posted July 30, 2009 Author Share Posted July 30, 2009 Web server. First I was testing it on my local web server, which is much slower than my paid hosting. So yea, same as what I said before, when it runs on a faster server it's like constant information 'pouring' in. But locally (slower) it's like stop and go. Quote Link to comment 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.