让我们用两个示例进行测试:
$memory = (int)ini_get("memory_limit"); // Display your current value in php.ini (for example: 64M)
echo "original memory: ".$memory."
";
ini_set('memory_limit','128M'); // Try to override the memory limit for this script
echo "new memory:".$memory;
}
// Will display:
// original memory: 64
// new memory: 64
?>
上面的示例不适用于覆盖memory_limit值。但这将起作用:
$memory = (int)ini_get("memory_limit"); // get the current value
ini_set('memory_limit','128'); // override the value
echo "original memory: ".$memory."
"; // echo the original value
$new_memory = (int)ini_get("memory_limit"); // get the new value
echo "new memory: ".$new_memory; // echo the new value
// Will display:
// original memory: 64
// new memory: 128
?>
您必须将ini_set('memory_limit','128M');放置在文件顶部或至少在任何回显之前。
对于我来说,suhosin并不是解决方案,因为它甚至都没有出现在我的phpinfo()中,但是这样做有效:
ini_set('memory_limit','2048M'); // set at the top of the file
(...)
?>