views:

147

answers:

2

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

+1  A: 

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.

soulmerge
what? hidden second parameter?
thephpdeveloper
afaik there is just that one parameter to reveal actual system usage, and yes I'm using it. I'm afraid I can't paste the code. I use a class called amazon-s3-php-class, which buffers local files for upload through CURL.From what I've tested, this seems to be the case, and I need to be able to empty that buffer, or tell GC to delete it right away of some sort.
dropson
@thephpdeveloper: Correct, should have been '*first* parameter'. Fixed.
soulmerge
@dropson: Could it be that the class you're using is setting globals or static variables in the class?
soulmerge
@soulmerge: The issue lies in GD which is loaded as an extension in PHP and probably not managed by the php memory manager. Thus, when freeing the resource, it's freed internally with PHP, but not in system, until gc has unloaded the resources somehow. I'm installing PHP 5.3.2 from source, to check out the new gc_collect_cycles() function, to force GC.
dropson
A: 

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.

dropson