PHP Possible Memory Leak

2019-08-24 02:28发布

I have a script that loops through a database for images to convert with gd & imagick.

I unset or replace all variables and objects in between each loop.

For each loop, get_memory_usage(1) reveals a concurrent amount of memory used by that script. Which is expected.

But, when I run "top", the %MEM column reports that this script, (same PID), increments with several percentages for each loop.

I destroy all images when I'm done with them, and when I run get_defined_vars(); only the standard globals and a few variables I have is set.

Why is "top" % Memory Usage different than what PHP reports?

After 10 loops, PHP has taken 20% percetage of the system memory.

I run php 5.2.6 on Debian 5

2条回答
女痞
2楼-- · 2019-08-24 03:15

I'll have to answer this one my self.

Upgrading to PHP 5.3.2 eliminated the problem with garabage stacking up at such big ratios.

Because there is some leaks I can't identify, and reset in terms of GD image resources filling up no matter what I do, I've decided to have a perl script run the while loops, and executing the PHP script

system("php /opt/cron/tasks.php");

This way PHP always empty the buffer/memory.

查看更多
相关推荐>>
3楼-- · 2019-08-24 03:26

Are you passing the first parameter to memory_get_usage()? If not, you should try that first. For any further information, we would need your source code.

查看更多
登录 后发表回答