PHP Memory issues in PHP5 as well?
| From: | Benjamin Smith | Date: | Wed, 24 May 2006 18:54:22 +0000 |
| Subject: | PHP Memory issues in PHP5 as well? | ||
| Groups: | php.gtk.general | ||
| Request: | Send a blank email to php-gtk-general+get-6945@lists.php.net to get a copy of this message | ||
I have a fairly large codebase that will have to be majorly refactored
switching from PHP4/GTK1 to PHP5/GTK2. I've been considering this as an
opportunity to pay down on some technological debt, and make more use of
classes rather than our current layout of "lots of functions" with GTK
widgets saved in a globally accessed array.
But, based on this thread, that may well turn out to be a very bad idea,
leading to stability problems. Are these memory issues (not freeing memory
when allocated inside a function or PHP class object) also present in PHP5?
Can anybody confirm that unref() solves the problem that unset() does not?
Also, does anybody have any script that consistently reproduces the problem? I
wrote the following to see if I could reproduce this memory bug, and it
didn't have any problem with PHP4 on Fedora Core 3:
############################################
set_time_limit(0);
Function SuckupRam()
{
$student=array();
for ($i=0; $i<10000; $i++)
$student[]='asdfasdfasdfasdfasdfasdfasdfasdf';
return true;
}
while (true)
SuckUpRam();
############################################
Run for several minutes, this script used up 0.2% of system RAM. Tried again,
this time with random variable names:
############################################
set_time_limit(0);
Function RandomChar($length=0)
{
$min=ord('A');
$max=ord('z');
if (!$length)
$length=rand(1, 50);
$return='';
for ($i=0; $i<$length; $i++)
{
$return.=chr(rand($min, $max));
}
return $return;
}
Function SuckupRam()
{
$var=RandomChar();
${$var}=array();
for ($i=0; $i<10000; $i++)
${$var}[]='asdfasdfasdfasdfasdfasdfasdfasdf';
return true;
}
while (true)
SuckUpRam();
#############################################
Same result. Where is this memory leak an issue? Has anyone confirmed that
this is a language issue and not a bug in the PHP script?
-Ben
--
"The best way to predict the future is to invent it."
- XEROX PARC slogan, circa 1978