Drupal 7 site maxing out memory when saving node - php

When saving a particular node, my Drupal 7 hits a WSOD and this shows up in the error logs:
PHP Fatal error: Allowed memory size of 633339904 bytes exhausted (tried to allocate 84 bytes) in /var/www/mysite.org/includes/form.inc on line 1780, referer: http://mysite.or/node/193/edit
Saving other nodes, it appears to be a problem with this node. How can I figure out what function is maxing out the memory? How do you even begin to debug something like this? It would be more helpful if Drupal logged an error in watchdog but there's nothing there either.
PHP as you will see, has a generous 600M of allowed memory (this is a large site with 16GB of RAM).
Any ideas?

You can, technically, catch the error in a shutdown function:
register_shutdown_function(function() {
var_dump(error_get_last());
});
But it won't be very useful seeing that you already have the type, file and line where the problem is occurring. In practice, you'll usually want to follow what's going on by inserting debug_backtrace(), var_dump() and die() statements where needed.

Related

In PHP, how do I detect which was the *actual* script that caused a fatal error (memory size exceeded)?

I keep getting a mysterious error like this logged:
PHP Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 134217736 bytes) in C:\BLABLABLA\unrelated.php on line 24
Of course, unrelated.php is not the script that does the actual function call. It's just one of the many files with wrapper functions in my framework.
My extended PHP error logger, which uses debug_backtrace() in order to be able to loop through and log the "full chain" of function calls leading up to the error. However, even that "smart" logger of mine falls short in this case:
Allowed memory size of 1,07 GB exhausted (tried to allocate 134,22 MB):
Row 310 # "C:\BLABLA\debug.php"
Row 1844 # "C:\BLABLA\irrelephpant.php"
Neither of those files is the origin script which is actually run, resulting in this error.
All of the files mentioned above are never run directly. They are just part of my framework, wrapping functions from PHP or each other.
I don't understand this. Everything about debug_backtrace() seems to suggest that it will find the "outermost"/base script, but it clearly doesn't in this case. I assume it's because a FATAL error...? What can I do to make it truly log the actual script that was run in CLI and ended up causing this error? (So that I can assign more RAM for it specifically.)
You can use the Xdebug profiler to see where the maximum memory is allocated. You can increase memory size by adding this line in your unrelated.php script at top ini_set('memory_limit', '512M'); or whatever memory size increase you need.

Allowed memory size error in Tbs library

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

Concrete5 PHP GD running out of memory

I ran into this rather annoying issue the other day; when a page tries to load it will just 'stop' half way through returning half a page to the end user. The exact error is shown below.
[03-Jul-2015 03:15:04 Europe/London] PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 18996 bytes) in [path]/concrete/vendor/imagine/imagine/lib/Imagine/Gd/Image.php on line 602
I spoke to my host and they bumped up PHP's memory to 512M (which is a bit overkill) yet it still throws this error. I'm not sure if it's a memory leak in Concrete5 somewhere or if it is just the server that the site is hosted on.
Any suggestions are much appreciated.
Edit: Forgot to mention I'm running 1.7.4.2
Edit 2: For reference the exact function is imagecreatetruecolor()
Either:
ini_set('memory_limit','256M');
Inside PHP or getting your host to bump up the memory limit will do the trick.

PHP Fatal error: Allowed memory size - on a non-existent line

I'm seeing this error in my production server, sometimes (I mean, it seems random, as my site as a decent traffic and so far it just happened 5 times):
[21-Feb-2012 23:43:19 UTC] PHP Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 261900 bytes) in /home/xxxxx/xxxxx/xxx.php on line 1811
The funny part is, the file has only 798 lines, and this never happened before to me.
It may have to do with recent changes I made to my scripts, yes, but this error simply doesn't make sense to me.
Please keep in mind that I know what "Allowed memory size exhausted" error means, and I know how to increase the memory limit.
However, my question here is, why is PHP referring to a line that doesn't exist?
I don't know how to fix this problem, because this makes no sense to me.
Thank you.
I've just found what was causing this memory leak.
It was a recent change that was entering in recursion cycle between two functions, although it was a rare event.
The line 1811 is real, yes, but the file that the error was referring is not correct. The line 1811 was from another file (included on that referred one) where one of the functions is.
I still appreciate the help from the people who commented above.

PHP Fatal Error caused by Magento

So I'm checking my error logs and notice a bunch of these:
[20-Aug-2010 15:06:32] PHP Fatal error: Allowed memory size of 262144000 bytes exhausted (tried to allocate 16 bytes) in /home/website/public_html/lib/Zend/Db/Statement/Pdo.php on line 294
So I know that this has to do with the memory size set in php.ini, but it has been set to 250mb, which seems pretty high already for a VPS. There's quite a few of these errors, however front end performance is not affected.
Is it possible that I'm leaking memory somewhere, or is this a minor error?
Update: this is on a myriad of files:
app/code/core/Mage/Core/Model/Config.php
app/code/core/Mage/Eav/Model/Entity/Attribute/Abstract.php
lib/Zend/Db/Select.php
Mostly on models it appears?
512mb is recommended and on our sites we use it.
There might be situation (ex: reindexing) where You can have problems.

Categories