Today, we are going to have a look at solving PHP memory problems – which for most of you will be evident when using some form of site software such as Joomla!, WordPress or other similar pieces of software.
Signs that you are having PHP memory problems include, but are not limited to, the following:
- Pages not fully loading.
- ‘Out of memory’ error messages.
- Failure of components / plugins / features to work as expected.
Of course it should be noted that there can be other causes for these errors, but PHP memory problems are a chief culprit, especially if you are seeing a combination of the side effects above.
It is even more likely to be a PHP memory issue if you have just installed a new plugin or added new features.
Now, if it is a PHP memory problem, you may notice somewhere on the affected pages a message similar to this:
“Fatal error: Allowed memory size of 33554432 bytes exhausted”
You’ll probably also notice after this message that there is a (usually long, judging by the line number referenced!) PHP file referenced there. The numbers of bytes may be different for you as this refers to the maximum memory currently allowed to PHP scripts and software on your web hosting account (or server). The numbers above represent a current limit of 32MB (which is fairly standard – although some shared hosting accounts are known to be limited to 8MB to prevent abuse).
Now, if you manage your own server (dedicated, semi dedicated, VPS, reseller etc) then you’re in luck! It couldn’t be easier to solve!
Access WHM (or your equivalent server management control panel) and go to:
Service Configuration >>> PHP Configuration Editor
From here, go to the text box with the section listed as “Core” and the directive listed as “memory_limit”.
There will be a value in this box. As you’ve got a PHP memory error, this isn’t high enough at the moment. Although I must caution you, it is not advisable to set the limit to -1 (no memory limit) as this can cause a script to rapidly eat and eat all your memory and make the server crash – which is obviously something that I expect most of you do not want to happen!!
For most people that manage their server, this limit will have defaulted to 32MB. Increasing it to 64MB will solve most of these PHP memory issues fairly permanently (of course depending on the nature of your website, its complexity and how many plugins and extra features you add to it). In any case, it should be more than suitable for now – if not, it would be advisable for you to check for malicious scripting activity or bugs as no PHP script or software should be eating memory that fast!
Click the ‘Save’ button at the bottom and you have successfully upgraded the memory limit for PHP scripts – no server reboot or service restarts required!!!
If you are on a shared server, you might be out of luck – and you’re probably going to have to talk to your host about this. Obviously you won’t have access to WHM and would require your host to make these changes – however they likely will not do this in a shared server. The easiest solution in this case would be to upgrade your account to something where you have a bit more control – maybe a VPS. The likelihood is that if you are requiring quite an increase in your PHP memory limit that you are outgrowing your shared package anyway.