PHP可能的内存泄漏 [英] PHP Possible Memory Leak

查看:83
本文介绍了PHP可能的内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本可以遍历数据库,以便图像通过gd&想象中.

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.

对于每个循环,get_memory_usage(1)揭示该脚本使用的并发内存量.这是预期的.

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

但是,当我运行"top"时,%MEM列报告此脚本(相同的PID)在每个循环中以几个百分比递增.

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

当我用完所有图像并且运行get_defined_vars()时,我会销毁所有图像.仅设置了标准的全局变量和一些变量.

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.

为什么"top"%内存使用率与PHP报告的不同?

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

经过10次循环后,PHP占用了系统内存的20%.

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

我在Debian 5上运行php 5.2.6

I run php 5.2.6 on Debian 5

推荐答案

我必须自己回答这个问题.

I'll have to answer this one my self.

升级到PHP 5.3.2消除了垃圾以如此大的比率堆积的问题.

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

因为我无法识别某些泄漏,并且无论我做什么都需要根据GD映像资源的填充情况进行重置,所以我决定让perl脚本运行while循环,并执行PHP脚本

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");

这样,PHP总是清空缓冲区/内存.

This way PHP always empty the buffer/memory.

这篇关于PHP可能的内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆