Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 4034460 bytes)

cimmer
cimmer used Ask the Experts™
on
Im getting the following while creating a big string.

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 4034460 bytes) in /home/httpd/vhosts/website.com/httpdocs/feeds/feed.php on line 349

Any ideas on how to correct this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2005

Commented:
Try setting memory_limit higher in php.ini
Top Expert 2005

Commented:
heres my reply in the other question:

 yes by default the maximum allowed memory for a script is 8mb which is the equilivant to 8388608 bytes

for some reason your script is using up more then 8mb of memory

either theres a bug in your script or the output is very large

you need to increase the value in the ini setting

if you have access to your php.ini file incrase the value in this line

memory_limit = 8M      ; Maximum amount of memory a script may consume (8MB)

if not you should be able to change it using the ini_set function (look it up in the manual @ php.net)

Diablo

      
      
Top Expert 2005
Commented:
here try putting this at the top of your script

ini_set("memory_limit","20M");

thats for 20mb, increase it more if needed

Diablo
Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Author

Commented:
Are there any dangers to setting that too high?
Top Expert 2005

Commented:
if your system has enough memory to support it and other processes then no

if its an actively running script they you might want to look into reducing the amount of resources it requires however if it is only go to be run every so often i wouldnt see it as a big issue

Author

Commented:
it will only be run once a month or so
Top Expert 2005

Commented:
not a problem then in my opinion

the only real risk is if there were lots of users running the script simulataneously then your systems resources would be eaten up very quick but as this is not the case your system should have no trouble coping with it.
If your script uses that much memory it might take longer than 30secs to run ... add this line

ini_set("max_execution_time","3600");

Otherwise your script will bomb out after 30 seconds!

http://www.downplay.co.uk
PHP Development, Web & Database Design
Top Expert 2005

Commented:
Random_Pete it is a serious violation of the EE rules to use your business name as a signature
http://www.experts-exchange.com/Community_Support/help.jsp#hi106
I apologise, I wasn't aware. Is there a way I can remove it from my posts?
Top Expert 2005

Commented:
quite alright i was just letting you know so you don't get in trouble with mods in the future.

You can't remove it yourself, you could post a request in community support to get them removed from your comments, im not sure how strict the mods are on enforcing the policy but you may well be ok to just leave them and not include the tag in future posts.

Thanks, Diablo
Ok, thanks for the warning ...
It's not necessarily the script using too much memory. It could have to do with a known problem (memory leak) in php 4.2. I see this same error when running PEAR, And I'm assumming PEAR is not trying to use more than 10M of memory. You'd have to have a pretty horrific piece of code to use up 10M in a single script (except when handling large binary files maybe :)

The rumored fix is an upgrade to 5 *or* increasing your memory until you don't see that error anymore. But I tried to install a PHP app that would not work even when I set the limit to 300M!! So I'm going to upgrade to 5.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial