I want to share something that happened to me on the way.
I uploaded an image to my website and after that I created some thumbs. Those thumbs where being cropped automatically from relatively big files (jpeg images of about 5mb), and I was doing that lots of times. Suddenly, when uploading a big file and doing a thumb from a cropped image (not the original), I found out this error:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 22464 bytes)
How could I exhaust 128Mb of memory?
The main problem was I was using more memory than the available. The first thing to check was, of course, if I was uploading a correct file and not one too big. Ok, 3Mb. Then, which was the problem?
Normally, this kind of error comes with the exact line where it completely depletes your available memory. In my case, was inside this one:
$orig = imagecreatefromjpeg($fullPathFilename);
So, the server crashed when allocating a new image into memory. And then, this came to my mind: I didn't free any of the previous allocation calls! As aforementioned, I happened to generate lots of thumbs from multiple sized images. And silly me, I didn't free any of those. So, if you happen to see this error when you crop/resize/alter multiple images, check for this call inside your code:
imagedestroy($orig);
So, to sum up.
If you don't find the imagedestroy() function, then you may have found your problem!
I have also encounted with this problem
Increase the following variables so that your page execution will not stop:
max_input_time
memory_limit
max_execution_time
Cheers
Related
Hello i am facing the problem of Allowed memory size error. I have created the project in codeigniter, php and I have used Tbs library. Its worked fine but today it display the error:
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 258010 bytes) in
/home/abc/public_html/application/libraries/Tbs.php on line
4222
Please give me any suggestions.
If you are using TBS + OpenTBS in order to merge an XLSX file , then there is a known problem fixed with OpenTBS version 1.9.2 : if the number of row to merge is quite numerous, then you can have a very long process or a memory size error when calling $TBS->Show().
Use OpenTBS 1.9.2 or higher which is optimized for this point, and if the process is still long you can optimize more using the OPENTBS_RELATIVE_CELLS command.
"Allowed memory size of XXXXXX bytes exhausted" is a typical error when you don't have, as it's own name says, enough memory available for the php query to run.
Try upgrading memory_limit variable on your php.ini file, or by setting up ini_set('memory_limit', 'XXXM'); on your PHP file that you are running, being XXX the amount of Mb memory that you want to define.
If this isn't the case, you might have a bug in your software that is causing, i.e. a loop that is consuming memory without any control; but as you have said that it did work before...
Anyway, please check all the other answers from StackOverflow on this aspect:
Fatal Error: Allowed Memory Size of 134217728 Bytes Exhausted (CodeIgniter + XML-RPC)
CodeIgniter Fatal error: Allowed memory size of bytes exhausted
Codeigniter - Allowed memory size exhausted while uploading
Generally this type of occurs when your script is using too much memory. This can often happen in PHP if you have a loop that has run out of control and you are creating objects or adding to arrays on each pass of the loop. Check for infinite loops.
If that isn't the problem, try and help out PHP by destroying objects that you are finished with by setting them to null eg. $OldVar = null;.
Check the code where the error actually happens as well. Would you expect that line to be allocating a massive amount of memory? If not, try and figure out what has gone wrong.
Never upgrad memory_limit variable on your php.ini file, or by setting up ini_set('memory_limit', 'XXXM'); on your PHP file that you are running, being XXX the amount of Mb memory that you want to define.Letting application to eat memory he wants to is insane step.Try to find out bug does your application wants that much memory?? Find out
when I try to add new post, after clicking "publish" I have this fatal error:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 71 bytes) in /XXX/wp-includes/meta.php on line 776.
I spoken with my server admin and he can't give me more memory, so I tried to optimize WP by plugin WP-Optimize but this din't help.
I think wordprass is a good choice with alot of posts. Right now I have in wp_posts 5423 and wp_postmeta 32734 rows.(The website exists less than 1 year)
Any suggestion can be helpful.Thanks!
WP-Optimize won't solve your issue because its job is to clean the database.
You're PHP error has to do with the PHP Memory Limit.
If you have access to the code, then add the following in the "index.php" file of your Wordpress folder:
ini_set("memory_limit","128M");
If you have access to the server's "php.ini" file, then change the following:
memory_limit = 128M
It doesn't matter how big your database is. It's failing because your posting "probably" too much data (images, videos etc.) and it's going through a loop filling the memory, and when it reaches the limit, the script fails.
If it occurs every time you try to write a post, then you might want to look into the Wordpress plugins and their performance.
I'm having some problems uploading images in WordPress.
The images them selves are around 1-2mb and width/height is quite big 1000px+ X 1000px+ but the client wants to be able to upload them and let WordPress do the re-sizing.
However when trying to upload I'm getting the following error:
"Fatal error: Out of memory (allocated 28573696) (tried to allocate 4096 bytes)"
Now I understand that this means the server doesn't have enough memory to process the image but when I do a phpinfo() check on the server it tells me that I have 256M of memory.
So why would I be getting a fatal error message saying I'm only allocated 32M?
The website itself is hosted by someone else so I don't have access to a php.ini or any of the error logs.
Thanks In advance,
Mark,
Even with a very high memory limit, GD will run out of memory processing a full-size photo from a mid-level digital camera. If your server has ImageMagick on the command line, you could use that. When ImageMagick resizes an image it uses a relatively small amount of memory and it is not subject to the PHP memory limit.
I found a WordPress plugin called ImageMagick Engine that claims to make WordPress use ImageMagick instead of GD. I've never used that plugin myself though.
phpinfo may be showing you memory for the php config for the whole server rather then the shared account you are using. You may not be able to override with your own php.ini due to the main php config file restricting use of php.ini files.
Try adding the 'define" line below to wp-config.php a few lines of white space below the opening <?php in the file:
define('WP_MEMORY_LIMIT', '64M');
This may be able to override shared settings to give you more memory.
Turned out to be an issue with the company hosting the site limiting the memory allocated. Moved to a new host and the problem was sorted.
I have the following line of code, at the start of a function:
$src_img=imagecreatefromjpeg($name);
the $name contains the full server path to the non-publically accessible folder that contains the image, which is a 4.4MB JPG.
Normally when this problem has occurred, PHP needs more memory than is allocated to open the compressed image, and issuing a ini_set command to raise the member to 128MB solves the problem. However, in this case, it does not. I've tried raising to 256, 512 and 1024MB and still it comes back with an error:
Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 17152 bytes) in /imgprocess.php on line 83.
I've even tried using the (contraband!) -1 to allow unlimited memory, just to see if something was causing it to go sky high, but still no go.
I've tried a different image file incase it was a bad JPG, still no go.
How can this be solved?
EDIT: I should add that PHP isn't in Safe Mode
This should solve your problem:
ini_set('memory_limit', '256m');
Please read faq.using.shorthandbytes
Using "MB" is a wrong shorthand notation. ini_get() doesn't return normalized values most often it returns what it was set to.
I have some troubles with the function imagecreatefrompng(), in PHP.
I develop a website which has the goal to permit users to upload their own Sprite Comics (kinds of Comics made with ressources extracted from videogames, called sprites).
I want to display in their galeries some miniatures of their comics, so I use GD and, of course, imagecreatefrompng().
But it throw a fatal error with large images:
Fatal error: Out of memory (allocated 8388608) (tried to allocate
4545600 bytes)
The same error occurs even after setting the value of "memory_limit" via ini_set()...
After few hours of researches, it seems to be because of the resolution: imagecreatefrompng() can't manage images having more than 1 040 000 pixels...!
It's very very inconvenient, since I can't limit the size of comics sent by the users...
Do you know any tips to resolve this issue?
Thnaks in advance!
You need to ask your hosting provider to set more virtual memory. It's a setting in php.ini - memory_limit and shouldn't be problem to do it free. You are now on the most lowest value.