當我運行下面的PHP腳本但是做了一些統計數據,我的本地機器, 它init_set('memory_limit', 100M)
效果很好,同一PHP腳本執行,不同的內存需要
,當我在另一個執行相同的PHP腳本web服務器, 處理相同的文件(我相信這一點), 它不起作用。
我將memory_limit更改爲1000M,但它仍然不起作用,並給出異常:「致命錯誤:允許的內存大小爲1048576000個字節(已嘗試分配32個字節)」。最後我改爲init_set('memory_limit', 1300M)
,它的工作原理!
兩個mahchine的PHP版本都一樣:
PHP 5.3.6 (cli) (built: Mar 28 2012 02:18:34)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
with eAccelerator v0.9.6.1, Copyright (c) 2004-2010 eAccelerator, by eAccelerator
以下是主要的腳本:
protected function _insertTable($logType, $conf, $logFileName) {
$logPath = $this->_getLogDirPath($logType, $conf) . DIRECTORY_SEPARATOR . $logFileName;
$fileContent = file_get_contents($logPath);
if (!fileContent) return;
$fields = array_keys($conf['fields']);
$dao = new dao\StatLogDao($this->_entities[$logType]);
$lines = explode("\n", $fileContent);
$fileContent = null;
unset($fileContent);
foreach ($lines as $line) {
$line = trim($line);
if (!$line) continue;
$lineData = explode($conf['glue'], $line);
if (!$lineData[0]) continue;
$entity = $this->_getEntity($logType);
foreach ($fields as $k => $f) {
$entity->$f = $lineData[$k];
}
try {
$dao->replace($entity, $fields);
} catch (Exception $e) {
echo $e->getMessage() . "\n";
}
$entity = null;
unset($entity);
$line = null;
unset($line);
}
$lines = null;
unset($lines);
$dao = null;
unset($dao);
}
我完全糊塗了,似乎「未設置」贏得」沒有足夠的記憶,plz幫助我。非常感謝!!
感謝您的回答,但是,1:腳本通過crontab執行,不應該是關於權利的問題,即使是mysql 2.the mysql版本是'Ver 14.14 Distrib 5.5.21,對於使用readline 5.1'的Linux(x86_64)3。根據錯誤消息「致命錯誤:允許的內存大小1048576000字節耗盡(試圖分配32字節)」,ini_set()工作無論如何,當內存大小更大時,腳本可以按預期工作。 4.兩個php設置之間的主要區別是配置關於memcached,這是否重要? – RoyHu
只要你用cron運行這兩個腳本就沒問題。當您使用cron運行PHP時要小心,然後使用其他PHP.ini而不是用於Apache的那個!禁用Memcache進行測試。 – powtac