Allowed memory size of 268435456 bytes exhausted [duplicate] - php

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Allowed memory size of X bytes exhausted
I'm handling with a quite little big database (87mb) import and to do that I use a php script.
All the operations are made in locale with an apache installation on Ubuntu Lucid.
When I run the script after few minutes I receive this error:
Allowed memory size of 268435456 bytes exhausted
I've changed memory_limit to 2GB in php.ini file and restarted apache. After that I've checked phpinfo() and I see that memory_limit is set to '2048M' so all is ok.
But when i relaunch my script i receive the same error, 256mb memory limit exahusted.
Where am I wrong?

If the script you are using is borrowed from someone else make sure there is no ini_set('memory_limit', '256M') which would produce the exactly effect you are seeing in spite of any change you made in php.ini.

Ubuntu has two php.ini's, one for apache and one for cli.
Are you sure you edited the right one?
The one for command line is usually in /etc/php5/cli/php.ini.

Most probably wrong php.ini is used.
In the same phpinfo()-s output you can check what file is used exactly, search for "Configuration File".
You can call the phpinfo() function from your real script used, to be sure to get the settings for exactly your script (different settings can be used for different virtual hsots, paths, etc).

Related

Laravel Memory: 'out of memory (allocated 262144)'

I'm a system administrator which handles a server that hosts an internal api created using Laravel 5. The data source is a SQL Server hosted on another server and the api is used in a IOS app for mobile phones. When the developers created the api, this error was not present and no other memory errors were found. When we went live this error has been popping up from time to time.
[2015-06-01 23:01:52] production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Out of memory (allocated 262144) (tried to allocate 140189808036120 bytes)' in Unknown:0
I checked RAM, CPU, swap etc etc of the server but everything was ok. Not much of the resources are being consumed. I've checked PHP Memory limit from php.ini and is set to -1 which is the max according to PHP. I've checked it on CLI, phpinfo.php and httpd.conf I don't see anything wrong. The team tried following this link Allowed memory size of X bytes exhausted
This is a problem in the ios app because the app searches for a correct return code but when this error comes out, even if the ios app transaction is correct, it returns an error because the return code is incorrect as it is returning the code for the memory error.
The first thing I could think of was to restart the Apache httpd service. This immediately solved the issue. but I knew this is not a permanent fix for the issue. When I researched further, I got to know that the error comes when certain PHP scripts require more memory than PHP was allowed by default.
So the solution is to increase the memory allocated for PHP. How to do that? There are 4 possible ways –
Try looking for the php.ini file. You might find some redundant php.ini files, so make sure you have got the one which is actually being read by PHP. o be sure, create a new php file in your root folder, say “check.php” and have phpInfo(); within the php open and close tags. Execute this file to get the information on where the php.ini is residing. Normally it will be in /usr/local/lib/php.ini
Open the php.ini file in a text editor like TextPad (not in Notepad) and change the values for memory_limit. By default you should see memory_limit = 8M. Try changing it to 12M. If it doesn’t work, increase it to 16M or even 24M and so on.
In case you can’t find the php.ini file or do not have access to it, then open up the file which was throwing the error (admin.php in my case) and add a line below just after ini_set(’memory_limit’, ‘12M’);
You can even consider adding a line in .htaccess file which will resolve the issue.
php_value memory_limit 32M
Or else, Try adding this line to your php file:
Increasing memory allocated to PHP
ini_set(“memory_limit”,”16M“);

memory limit in php

I'm making a curl request , witch was working perfectly for weeks, and now it's returning this error:
Allowed memory size of 262144 bytes exhausted (tried to allocate 76889 bytes)
The weird part is that i've checked php.ini and phpinfo and both tell me memory limit is
memory_limit 1028M
I've also tried
ini_set("memory_limit","400M");
In the top of the file to make sure, but still, getting this error.
This is happening in both development and production servers.
DaveRandom nailed it. suhosin (I wasn't even aware we had that
installed) was causing de issue by "overprotecting" the server.
[forums.cpanel.net/f5/php-memory-limit-problem-69715.html][1] - TL;DR
it's being caused by suhosin. – DaveRandom
Thanks to all!
[1]: http://forums.cpanel.net/f5/php-memory-limit-problem-69715.html
UPS, that somehow fiexd the error in that part, but another part of the webapp is throwing same error.
I have no clue where to look at.
it says memory limit is 1028M in php info, if i change it via ini_set, new value appears using ini_get, and now I have set suhosin to simulation. that somehow fixed the first problem, but now it reappeared.

Allowed memory size exhausted in both Joomla and Drupal

I am trying to set up a website using Joomla and this is the error I get after accessing localhost (right after successful installation process):
Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 98304 bytes) in [...]\default_item.php on line 77
The same thing happens when using Drupal (before installation though). I have already tried changing php.ini (in location given by Joomla itself, so it's the right one. Interestingly, website on localhost does not work, while admin panel on localhost/administrator works, that's where I got the file location from) to look like this:
memory_limit = 512M
I also tried putting ini_set('memory_limit', '512M'); inside the script indicated in error and freeing some of my RAM, but still - no success.
I use WebServ, which uses Apache 2.2.6 and PHP 5.2.5.
What more can I do to overrun this problem?
Edit:
Output of phpinfo(); for Joomla
ini_set('memory_limit', '-1'); overrides the default PHP memory limit.
By the way look out for never ending loops. It might be causing the error.

php extract function cause memory exhausted when running on IIS

i got a very strange problem with my code running on PHP 5.2.8 + IIS6 ISAPI virtual host.
the page reports error "Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 536870912 bytes)" when i'm using the following code.
$comments = $Comment_Model->getComments(2, $logid, 'n', $commentPage);
extract($comments);
but if i'm not using the "$comments" to extract, no error reports.
extract($Comment_Model->getComments(2, $logid, 'n', $commentPage));
what i have tried:
increase more memory by adding ini_set('memory_limit', '') into my script, not works.
move the script to other servers, it works.
it looks like an environment problem, does anyone has a clue?
I had the same problem with ini_set() not working for upping the memory limit on my shared hosting. Depending on your server's setup, some ini options are not allowed to be changed via ini_set().
You may have to edit the php.ini file, which some hosting providers will allow, and some not. I would also suggest that you make sure your script really should need that much memory (not a problem with the code).
I hope that helps.

Allowed memory size of 33554432 bytes exhausted (tried to allocate 12 bytes) [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Allowed memory size of 33554432 bytes exhausted (tried to allocate 43148176 bytes) in php
hi,
i m tring to run the program, but I keep getting this error;
Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 12 bytes)
plz, help me
Here is a simple tutorial here it will work.
This error message can spring up in a previously functional PHP script when the memory requirements exceed the default 8MB limit. Don’t fret, though, because this is an easy problem to overcome.
To change the memory limit for one specific script by including a line such as this at the top of the script:
ini_set("memory_limit","12M");
The 12M sets the limit to 12 megabytes (12582912 bytes). If this doesn’t work, keep increasing the memory limit until your script fits or your server squeals for mercy.
You can also make this change permanently for all PHP scripts running on the server by adding a line like this to the server’s php.ini file:
memory_limit = 12M
Keep in mind that a huge memory limit is a poor substitute for good coding. A poorly written script may inefficiently squander memory which can cause severe problems for frequently executed scripts. However, some applications are run infrequently and require lots of memory like importing and processing a big data file.
In case you need any more help please do not hesitate to reply here.
There might be running infinite loop
paste your code here for better answer
Locate your php.ini file and edit the memory_limit field
Increase max_memory in your php.ini file.
Either increase the memory limit defined in php.ini, or rewrite your code to use less memory (e.g. by freeing up resources or variables that won't be cleaned automatically by PHP's garbage collection), or give us more detail so that we can try to help. "trying to run the program" doesn't really tell us much, eg. what program?
Before you change the memory limit you should check if your code needs that much memory in the first place. It's a very unusual scenario for that to be the case - usually this is an indicator of:
1) incorrect config elsewhere, e.g. in webserver
2) inefficient management of resources in your code
3) unbounded loops/recursion

Categories