3

Setting php_value memory_limit always involves a bit of guesswork and I myself tend to use higher than necessary values just to make sure that the odd memory hungry call does not result in a fatal error.

Still, I am looking for a shell script that would behave kind of like htop or top but instead of showing the current values it would remember only the maximum memory consumed by a PHP script and retain it. Such value, over a few days, would be a very valuable indicator of what php_value memory_limit should be set to. Does something like that exist?

1
  • 1
    setting a high memory limit doesn't mean PHP will automatically suck up that much memory each time. While setting a limit is a good idea, setting a high limit won't starve your system of memory unless you do have a bunch of misbehaving scripts. Commented Oct 25, 2011 at 15:30

2 Answers 2

6

What about saving the value returned by memory_get_peak_usage in a database/file?

Sign up to request clarification or add additional context in comments.

Comments

0

I guess this is very difficult to employ in a useful manner, because it depends on the structure and amount of data that you're processing.

Say you're measuring this week and have about 100 abstract rows of data. You settle on a number. In two months time, your site/app goes viral and you have 10000 abstract rows of data to process.

So what I am saying is this: while your measured value might be appropriate for today, it might not be for tomorrow if the data you process today is different from tomorrow's.


This link explaining php's memory manager could be of use: http://www.ibm.com/developerworks/opensource/library/os-php-v521/

2 Comments

Your arguments are the reason why I look for the maximum PHP memory size over time. Any instant or short term checking of the memory size only allows us to pretty much guess a safe value for php_value memory_limit, but if we have a week or two-weeks' maximum (which, as you say, should include peak usage), then the obtained value would be pretty much to what we need to set.
@Vacilando If you want to pursue this: I've added a link that seems useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.