Jump to content

Run a PHP script without running out of memory


soma56

Recommended Posts

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.