Measure maximum PHP memory usage

2019-04-12 13:09发布

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?

2条回答
迷人小祖宗
2楼-- · 2019-04-12 13:27

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

查看更多
疯言疯语
3楼-- · 2019-04-12 13:33

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/

查看更多
登录 后发表回答