问题描述
我在PHP中的内存问题。我已经设置php.ini中的限制512 M
i have a memory problem in php. I have set the limit in php.ini to 512 M
/var/log/apache2/error.log的输出是:
the output of /var/log/apache2/error.log is:
PHP的致命错误:允许内存大小 的536870912字节用尽(试图 分配71个字节)中 /var/www/phpgraphlib.php线578,
有趣的一张code是:
the interesting piece of code is:
foreach ($saved_test_figurestoprint as $figuretoprint){
if (strpos($obj[$figuretoprint],",") >0 ){
$graphfilename= "graphfile".remove_invalid_chars_for_file($obj["_id"])."_".remove_invalid_chars_for_file($figuretoprint).".png" ;
$graph = new PHPGraphLib(1000,200,$graphfilename);
$data = explode(',', $obj[$figuretoprint]);
$graph->addData($data);
$graph->setTitle($figuretoprint);
$graph->setBars(false);
$graph->setLine(true);
$graph->setDataPoints(true);
$graph->setDataPointColor('maroon');
$graph->createGraph();
?> <td> <? echo $figuretoprint ; ?></td> <td> <?
echo <<<END
<imag src=$graphfilename>
END
?> </td></tr><tr><?
echo "</br></br>";
echo "used memory is ".memory_get_usage(true) . "\n";
最新的输出:使用的内存为30408704
the latest output is :used memory is 30408704
我使用的是64位的Ubuntu和PHP 5.3。Linux的蒙戈-DB服务器2.6.35-28泛型#49,Ubuntu的SMP星期二3月1日十四点39分03秒UTC 2011 x86_64的PHP版本5.3.3-1ubuntu9.3如果有> 40的图像绘制问题出现了。
i am using a 64bit ubuntu and php 5.3.Linux mongo-db-server 2.6.35-28-generic #49-Ubuntu SMP Tue Mar 1 14:39:03 UTC 2011 x86_64PHP Version 5.3.3-1ubuntu9.3the problem arises if there are > 40 images to draw.
我认为新的内存限制没有被应用到服务器我发现这个bug http://bugs.php.net/52061 但只对内存的限制> 2GB
i think the new memory limit is not been applied to the serveri have found this bughttp://bugs.php.net/52061but is only for memory limits > 2GB
你能帮助我吗?
推荐答案
PHP取消设置只是删除了对象的引用,它不清除内部对象的内存分配,所以在反复的过程,你的每一次创建大型的对象,然后不要让你的对象的破坏作用,并在该函数没有设置每个类的变量使用,那么只能搅乱的主要对象将释放整个内存被占用..希望这一事实有助于任何人
PHP unset just removes the reference to the object and it does not clears the internal object memory allocation, so on iterative process where you are creating large objects every time then do make a destroy function of your object and in that function unset each class variables used, then only unsettling the main object will free whole memory it is occupying.. hope this fact helps anybody
这篇关于在PHP内存限制问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!