Reputation: 333
When i running the following php script to do some statistics in my local machine,
it works well with init_set('memory_limit', 100M)
,
however, when i executing the same php script in another web server, dealing with the same files(i am sure about this), it doesn't work.
I change the memory_limit to 1000M ,it still doesn't work, giving exception : "Fatal error: Allowed memory size of 1048576000 bytes exhausted (tried to allocate 32 bytes)". Finally i change to init_set('memory_limit', 1300M)
, it works!
The php versions in the two mahchine are the same as :
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
The following is the main script:
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);
}
I'm totally confused, it seems 'unset' won't free enough memory, plz help me out. Many thanks!!
Upvotes: 3
Views: 202
Reputation: 41050
You probably have different modules installed...
A lot of more things can cause your script to crash (is seems like a endless loop):
I'm pretty sure the error you are receiving is because your script goes wrong and not because of different memory usage. You also should check if the allowed memory size memory_limit
is really editable via ini_set()
. Check it with echo ini_get('memory_limit');
on both machines after you try to set it.
To be really sure that both of the servers are "same" dump the output of phpinfo();
into two files and do a diff
on them! Only the server names, unique ids and some dates should be different...
Upvotes: 2