soma56 Posted July 5, 2010 Share Posted July 5, 2010 I have a script that I recently created and it works great...for the first while. I'm trying to figure out different ways to 'optimize' it or otherwise run smoother. My script echo's thousands of lines of code while running through a loop. Firefox, after about an hour, runs so slow to the point of crashing. It is quite obvious - the program doesn't echo as quickly and performance is dramatically reduced. I've edited the memory limit by doing the following: ini_set('memory_limit','16M'); I've 'flushed' the buffer?: ob_flush(); flush(); usleep(500000); And I've also checked how much memory is being used during every 'parse': if ($mem_usage < 1024) echo $mem_usage." bytes"; elseif ($mem_usage < 1048576) echo round($mem_usage/1024,2)." kilobytes"; else echo round($mem_usage/1048576,2)." megabytes"; echo "<br/>"; It averages at about 10megs through every loop. Is there anything else I should be doing to increase the performance? Unloading or unsetting something? Quote Link to comment https://forums.phpfreaks.com/topic/206726-run-a-php-script-without-running-out-of-memory/ Share on other sites More sharing options...
trq Posted July 5, 2010 Share Posted July 5, 2010 Scripts like these aren't really designed to be executed via a browser. What exactly does the script do? Quote Link to comment https://forums.phpfreaks.com/topic/206726-run-a-php-script-without-running-out-of-memory/#findComment-1081127 Share on other sites More sharing options...
travo1992 Posted July 5, 2010 Share Posted July 5, 2010 I agree with thorpe that is probably the browser being sluggish rather than PHP. As far as I know, PHP doesnt slow down as it approaches the memory limit, only creates errors once it surpasses it. Does the browser need to maintain every line outputted? If not, perhaps you could echo out some js every few thousand lines to clear the window? Quote Link to comment https://forums.phpfreaks.com/topic/206726-run-a-php-script-without-running-out-of-memory/#findComment-1081226 Share on other sites More sharing options...
soma56 Posted July 5, 2010 Author Share Posted July 5, 2010 I agree with thorpe that is probably the browser being sluggish rather than PHP. As far as I know, PHP doesnt slow down as it approaches the memory limit, only creates errors once it surpasses it. Does the browser need to maintain every line outputted? If not, perhaps you could echo out some js every few thousand lines to clear the window? Ok, so it's likely the browser being sluggish by containing upwards of 40k to 60k lines of code? Nothing I can do except delete then lines every 10k perhaps through js? Quote Link to comment https://forums.phpfreaks.com/topic/206726-run-a-php-script-without-running-out-of-memory/#findComment-1081344 Share on other sites More sharing options...
travo1992 Posted July 5, 2010 Share Posted July 5, 2010 I already said that you will have to use js to do it. document.body.innerHTML='' Should do it for you Quote Link to comment https://forums.phpfreaks.com/topic/206726-run-a-php-script-without-running-out-of-memory/#findComment-1081607 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.