My joomla website started to show following error
Fatal error: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 78 bytes)
I know we can increase the memory limit using ini_set, but I believe it is not the correct way to solve this. Even though, if I set the memory limit to unlimited (-1), I will get an Internal Server Error. I am completely unaware about the recent activities on this site, as I am newly assigned to this task. I tried to disable some plugins and modules using DB. What I did is, just fetch the entries from _modules and _plugins with descending order of id and change the publish to 0. But nothing works. I am getting the same error (Fatal error: Allowed memory...). I tried to open the admin page, that is also not loading. Just showing a blank page.
Please help me to fix this. I am new to joomla
I don't believe you're going to receive a concise answer for this type of problem as it is far too broad. It sounds like you have a memory leak. See:
How to find which PHP script is leaking memory?
Diagnosing Memory Leaks - Allowed memory size of # bytes exhausted
Unfortunately, finding the cause of a memory leak is seldom a simple task. The two links above do provide some useful tips, namely placing calls to memory_get_usage and also the Xdebug extension.
Even if you weren't new to Joomla and more familiar with the code base, it probably wouldn't make solving this problem any easier.
Lets start with what that message is telling you.
PHP is saying I have successfully allocated a GIGABYTE of memory for this code to run with but I now need to allocate another 78 bytes but I cannot because I have reached my limit.
The part of that statement that should be shouting at you is Its already allocated a GIGABYTE of memory for this processing. That is just ridiculous.
Either as was suggested by #mistermartin some code is causing a memory leak or you have some code in the process that failed that is consuming ridiculously large amounts of memory
That message usually is associated with a stack trace telling you in which piece of code this error happened, and which piece of code called that, etc, etc.
Question: Does it always happen in the same piece of code? If so thats where you start looking.
I would start by looking through all the code in that stack trace, not just the particular script that actually broke the camels back so to speak. Work your way back through all the code that has been executed looking for something that has the potential to allocate hugh amounts of memory, arrays are a good place to start but they are not the only possibility.
I would personally copy the site ( complete with database ) to a test environment where you can either use a decent debugger to follow the code through an execution of the offending code.
If you cannot setup a debugger then at least in a test environment you can add some debugging code to tell you where and when memory starts to be consumed at this riduculous rate.
If you are looking for a way to fix this issue please follow the below methods. But it's not adviced to use it since it does not solve the issue you have with your program(code). You still should check why the memory is exhausted.
1 Using PHP Code
ini_set('memory_limit', '-1'); // This will take unlimited memory usage of server
Above method is not working for you as you say.
2 Using php.ini
Change the line in php.ini If your line shows 32M try 128M.
memory_limit = 128M ;
Maximum amount of memory a script may consume (128MB)
How to debug the code
Your program is consuming memory than it need. 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.
How to find which PHP script is leaking memory?
I am not too familiar with Joomla, but verified it redirects traffic through an index.php file similar to many other frameworks and apps. A decent first step to finding WHERE the leak is would be adding the following to the index.php file.:
function shutdown() {
$aError = error_get_last();
if ($aError["type"] == E_ERROR ) {
openlog("Fatal Error Shutdown Log: ", LOG_ODELAY, LOG_USER);
syslog(LOG_ERR, 'Message: ' . $aError['message'] . PHP_EOL);
syslog(LOG_ERR, "File: " . $aError['file'] . PHP_EOL );
syslog(LOG_ERR, "Line: " . $aError['line'] . PHP_EOL );
}
}
register_shutdown_function( 'shutdown' );
Check your syslog for the string "Fatal Error Shutdown Log:" and it should give you the specific location the memory leak is occurring. If Joomla has a more appropriate location to put this code, go for it. In theory shutdown functions will run no matter what. all this does is log only the fatal errors to your syslog. Memory errors are fatal errors. Good luck.
I have experienced a similar issue with ridiculously long SQL strings (inherited code was imploding a massive array into an IN condition). Log your SQL queries and check they dont exceed the max_allowed_packet (1GB)
http://dev.mysql.com/doc/refman/5.1/en/packet-too-large.html
You could start by enabling Joomla debugging. On Joomla 3 it's at the backend > global configuration > system > debug system
Then, on the front end of your site your template should give some debugging info.
I would start by looking for clues in the Profile Information and Memory Usage sections
Good luck!
Edit
Admittedly this is bit of a long shot, but maybe there are some Akeeba backups siting on the site that you could use. Look for some Akeeba .jpa files, probably in site_root/administrator/components/com_akeeba/backup/
If there are, I would start by restoring them to another machine so that you can rule out any server php related errors as well.
Maybe you'll be lucky.
I had this problem also - for my /administrator/ folder. None of the configuration or php.ini memory limit changes fixed the problem, which I tracked down to being connected to the fact that I'd changed the name of my /administrator/ folder in order to make it more difficult for hackers. Shouldn't have made a difference, if code was using relative paths, but apparently some code did not. Now, I rename the folder back to default to use admin features, then back to a random name to give the hackers a better challenge. So, have you changed any folder names??? I hope this helps someone.
Related
I have a staging server running a Yii application that now gives a 'white screen of death'. I cannot see anything being ouputted to the screen (or even the source code when 'view source'), locally the same code runs without any issues.
Can anyone suggest a good routine to debug 'white screen of death' within a Yii application?
Getting a blank screen in yii is mostly because error_reporting is off.
Put
error_reporting(-1);
ini_set('display_errors', true);
in index.php should get your output back.
Note that you can always look in application.log and apaches error.log for informations when you don't have some output.
This is for Yii2
I found the code was failing in vendor/yiisoft/yii2/BaseYii.php at method autoload($className). It was failing at execution:
include $classFile; (line 293)
The cause in my case was a function method name declared twice.
You might be interested to know that you can discover the cause (which Yii2 suppresses through its own error-handling) by preceding the command with Chris's recommended code above https://stackoverflow.com/a/25139283/3125602. If you introduce them too early in the code, they get overwritten by Yii2's error-handling settings.
It is quite a simple issue and happens either when a script reaches the PHP memory limit or during a plugin or theme conflict.
Solutions :
Increase the Memory Limit :
Since this is regarded as one of the cause, it is recommended that the PHP memory limit be increased. Edit your wp-config.php file via FTP adding the following line of code:
define( ‘WP_MEMORY_LIMIT’, ‘64’);
This increases your memory limit to 64M. You might need to contact your host before you do it as some host don’t allow it from your end.
Deactivate all your Plugins :
Connect to your site via FTP and rename the wp-content/plugins folder to plugins_old to deactivate all your plugins.
Here is a detailed answer to the infamous "White Screen of Death" problem. Thank me later :)
https://www.perceptionsystem.com/blog/wordpress-errors-solution/
I'm getting the following PHP error when attempting to upload a file that is too large:
POST Content-Length of 1034425027 bytes exceeds the limit of 33554432 bytes in Unknown
But I have the following set in my controller:
$config['max_size'] = '10000';
All the solutions I see involve increasing post_max_size etc… but I don't want to allow larger files to be uploaded - I want an error, just the CI one, not a PHP one I can do nothing with.
Any ideas? Is this just a flaw in PHP? I'd rather not process the 'false' return in the ajax as a file upload error, because technically that could be produced from any server error.
EDIT; To clarify, as I'm getting requests for code that won't shed any light on anything (I can only assume the question is being misunderstood):
If the file is between 10mb (the limit set by CI) and 32mb (the limit set by post_max_size) everything works fine - there is no code issue. But if the file is large than 32mb PHP catches the file before CI can parse it and provide me with proper errors, so I have no chance to properly flag large files unless I make post_max_size infinitely large - which seems both dangerous and flawed. I'm wondering if there's a way around this. Ideally I don't need the server to get involved until after the CI validation, as I'd rather flag a user friendly error than the POST to just die.
Best bet would be to check the filesize with js [1] before attempting the upload. Short of this, the only options are to increase post size or create your own error hander [2].
[1] https://stackoverflow.com/a/7497439/183254
[2] http://www.php.net/manual/en/function.set-error-handler.php / https://stackoverflow.com/a/11745361/183254
First increase the size in php.ini i.e. upload_max_size. By default PHP settings will be read by php code and then codeigniter settings. So increase the size from .ini file.
I'm posting because after hours of searching I'm utterly confounded. Here's the deal. My Laravel application uses the PHP Image Workshop bundle. Everything seems to be working fine, except if I try to make a resizeInPixel() call or a cropInPixel() call (or similar calls) the server throws an internal server error. If I investigate the error log I see:
Premature end of script headers: index.php
This only occurs when I use the resize and crop related methods (i.e. image processing). I can initFromPath() with no issue, and I can use the save() method without issue. Only the image processing methods cause the internal server error.
I've also read online that this can be the result of a suphp_log file exceeding 2GB. I've tracked down and cleaned out that file, but to no avail.
Any thoughts are most welcome! Even if they're just general "have you tried...".
UPDATE
I've narrowed it down to a particular line in the Image Workshop code. This line is causing the error:
imagefill($image, 0, 0, $color);
Additionally, this error only occurs when the color is created using imagecolorallocatealpha, NOT when it is created using only imagecolorallocate.
There are some great hints for solving this issue at Liquidweb.com. My money is on #2 (see bold text) because you are getting the error when doing image manipulations:
Sometimes when executing a script you will see an error similar to the following:
Premature end of script headers: /home/directory/public_html/index.php
This error occurs because the server is expecting a complete set of HTTP headers (one or more followed by a blank line), and it doesn’t get them. This can be caused by several things:
Upgrading or downgrading to a different version of PHP can leave residual options in the httpd.conf. Check the current version of PHP using php -v on the command line and search for any lines mentioning another version in the httpd.conf. If you find them, comment them out, distill the httpd.conf and restart apache.
The RLimitCPU and RLimitMEM directives in the httpd.conf may also be responsible for the error if a script was killed due to a resource limit.
A configuration problem in suEXEC, mod_perl, or another third party module can often interfere with the execution of scripts and cause the error. If these are the cause, additional information relating to specifics will be found in the apache error_log.
If suphp’s log reaches 2GB in size or larger you may see the premature end of scripts headers error. See what the log contains and either gzip it or null it. Restart apache and then deal with any issues that the suphp log brought to light. The suphp log is located at: /usr/local/apache/logs/suphp_log
The script’s permissions may also cause this error. CGI scripts can only access resources allowed for the User and Group specified in the httpd.conf. In this case, the error may simply be pointing out that an unauthorized user is attempting to access a script.
UPDATE:
After some more info in the comments, I still feel this is a memory related thing.
According to this SO wiki: About gdlib
Warning: Image functions are very memory intensive. Be sure to set memory_limit high enough
What is your PHP memory_limit? Can you crank it up a bit?
In my php.ini file I have
memory=40M
What does this do (it solves some problems that I have been having). Note that this is NOT:
memory_limit=128M
I know memory limit sets the maximum amount of memory a PHP script can use, but what does memory do?
EDIT
I recognize this is not a standard directive, but it is fixing my problem. Without it my pages randomly produce 500 errors, but then I put this line in and they go away.
This is where I got the fix from:
http://www.archtopia.com/2010/01/30/wordpress-internal-server-error-500-with-1and1-webhosting/
memory is not a valid php.ini directive. It may be solving your problem because it is not recognized, in turn resorting to a default value that does in fact work. Also note that "megabyte" should be M not MB.
The proper way to set the value is:
memory_limit=40m
I can't find the memory directive on http://php.net/manual/en/ini.core.php. Are you sure it's correct and not a typo?
I have a script in production - an ecommerce checkout page - that has had some errors in the past that have prevented it from working and have cost me money. I wanted to get notified on errors so I worked this up:
<?php
function mailErrorHandler($errno, $errstr)
{
echo "<!--PHP ERROR:";
echo "---[$errno] $errstr ---";
echo "-->";
error_log("Error: [$errno] $errstr",1,
"myemail#myserver.com","From: me#workserver.com");
}
set_error_handler("mailErrorHandler",E_ALL);
echo 1-thisisnotanumber;
?>
When I use it as-is in it's own script, it works and executes quickly. However, when I add it to my existing application, the page load time decreases DRAMATICALLY i.e. 40 seconds as opposed to <1 second. Can anyone think of a reason why this might be happening?
If you have a significant amount of traffic and you're throwing a LOT of errors, writing to the log can cause a significant amount of disk IO. This can slow down your app to the extent that you're talking about.
Maybe what you're throwing isn't errors, but rather a bunch of Notice "exceptions". If you have them set to not display (the default in most versions of PHP) and you're getting a boat load of them, you could be running your error handler hundreds and hundreds of times. Every time the handler is run, it has to do a trace, break out of the current scope, do all sorts of processing, and if that's all happening because you're using =& new with PHP 5.3 or trying to access undefined array elements (or any other common notice), you're going to see those kinds of delays.
So in order to fix this, the doctor prescribes turning off the error handler on your test server, turning on the display of notices, run through the flow and take note of any errors/notices/etc, then fix the aforementioned notices on your production box.
Hope this helps!
Hmm. When you say "use it on it's own", do you mean in a separate page that is invoked through Apache, or are you running it on the command line? The delay, combined with the use of email makes me suspect a DNS or network issue...something not resolving or not connecting and timing out.
Another thought...fire up Xdebug and do a profile dump while this is running and see if that sheds any light on what is taking all the time.
Try to add an exit() after the error_log() call.
An other solution would be to log to a file if you have problems with the error_hander:
Set
log_errors = On
html_errors = Off
error_log = log
in your php.ini, then all the errors will be logged into the default error.log of your server.