These forums are locked and archived, but all topics have been migrated to the new forum. You can search for this topic on the new forum: Search for Plenty of memory but: Fatal error: Allowed memory ... exhausted on the new forum.
Hi
I tried to run a simple script today and got a Fatal Error:
Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 16 bytes) in /home/guru54gt5/public_html/sys/gift_run2.php on line 9
According to my VirtualMin home page I have: Real memory 947.38 MB total, 587.58 MB used
The code is just reading in a 3.34MB file:
$geo_path = $_SERVER['DOCUMENT_ROOT']."/sys/geo_ip_sm.csv";
Line 9 is: $geo_arr = file("$geo_path");
Any ideas why this fatal error is occuring when I should have loads of memory available to read in this file?
Thanks
Sounds like the memory allowed by PHP for that particular script has been exceeded.
You can tweak the php.ini values for your system -- if it's a Virtualmin Pro system, that's typically $HOME/etc/php.ini. If it's Virtualmin GPL, by default it would use the php.ini in /etc.
What you're looking for is "memory_limit" -- and you may want to bump that up a little higher.
-Eric
Thanks for the reply.
I have found five memory elements.
Maximum memory allocation 32Mb
Maximum file upload size 2Mb
Maximum input parsing time 120 seconds
Maximum HTTP POST size 8Mb
Maximum execution time 120 seconds
Is it the first one that I should increase?
What would you recommend ? Does it have to be in set intervals? Would 40 or 48Mb be OK ?
Does the Max File Size effect what I am doing ? Should I increase that to say 8 MB ?
Thanks
PS If I have got 32 MB why is the memory running out at 16.7 Mb ?
Hello,
I have increased the following:
Maximum memory allocation 32Mb => 48 Mb
Maximum file upload size 2Mb => 8 Mb
Just ran the script again and got same message: Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 39 bytes) in /home/guru54gt5/public_html/sys/gift_run2.php on line 16
My script is quite short. This is it it:
$geo_path = $_SERVER['DOCUMENT_ROOT']."/sys/geo_ip_sm.csv";
$ip = $_SERVER["REMOTE_ADDR"]; $ip = long2ip(ip2long($ip)); $ip = sprintf("%u", ip2long($ip)); $ip_country = "none";
$geo_arr = file("$geo_path");
for($i=0; $i<count($geo_arr); $i++) { $arrayOfLine = explode(',', $geo_arr[$i]); if($ip >= $arrayOfLine[0] && $ip <= $arrayOfLine[1] ) { $ip_country = $arrayOfLine[2]; break; } // endif
} // end for loop
echo "
IP: $ip
Country: $ip_country"; exit;
The file "geo_ip_sm.csv" is only 3.34 MB so I really do not see why there should be any problem :(
I just checked my system information and it shows Real memory 947.38 MB total, 444.89 MB used and Virtual memory 1 GB total, 476 kB used
Why can I not run this script ?
Any ideas ?
Where did you change the maximum memory allocation? The error says the system has only 16Mb available, not 32Mb or 48Mb.
Chris
I am running VirtualMin Pro
so I changed it under Services -> PHP 5 configuration.
This seems to change this file: /home/guru54gt5/etc/php5/php.ini
I ALSO changes it under Webmin --> PHP Configuration
This seems to change this file: /etc/php.ini
Anyway, BOTH say the same thing.
48Mb memory and 8Mb file upload.
I do not know where the 16.7Mb figure is coming from :(
I restarted Appachie as well.
OK - it seems to be working ok now.
It looks like when I changed the /home/guru54gt5/etc/php5/php.ini and restarted apachie that it worked.
Thanks