【发布时间】:2023-03-28 06:01:02
【问题描述】:
我在 php.ini 中有一个内存问题。我已将 php.ini 中的限制设置为 512 M
/var/log/apache2/error.log 的输出是:
PHP 致命错误:允许的内存大小 536870912 字节用尽(试图 分配 71 个字节)在 /var/www/phpgraphlib.php 第 578 行,
有趣的代码是:
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
我使用的是 64 位 ubuntu 和 php 5.3。 Linux mongo-db-server 2.6.35-28-generic #49-Ubuntu SMP Tue Mar 1 14:39:03 UTC 2011 x86_64 PHP 版本 5.3.3-1ubuntu9.3 如果要绘制的图像超过 40 张,就会出现问题。
我认为新的内存限制未应用于服务器 我发现了这个错误 http://bugs.php.net/52061 但仅适用于内存限制 > 2GB
你能帮我吗?
【问题讨论】:
-
如果有你最后一行的输出,我可能会很有趣(使用的内存是...)。
-
破坏/取消设置你的 PHPGraphLib 类...
-
我添加了 unset($graph); echo "使用的内存是 ".memory_get_usage(true) 。 "\n"; echo "内存峰值是 ".memory_get_peak_usage(true) 。 "\n";并且输出仍然处于同一水平使用内存为 30670848 内存峰值为 34340864。与我的 512MB 限制相比,这太低了
-
你好。我已经解决了这个问题。似乎mongo数据库中有一个特定的条目导致了它。由于某种原因,它保留了大量的内存。它可能已损坏。我已将其删除,现在一切顺利。