When accessing your site, or for any operation, the following error may appear :
Fatal error: Allowed memory size of 94371840 bytes exhausted (tried to allocate 262144 bytes)
Where does this error come from?
The PHP memory error comes from the fact that you don’t have enough memory to perform the action you want.
This can happen when you have a very greedy script for example. PHP has a limited amount of memory. When this limit is reached, you encounter the error mentioned in this article.
PHP is a powerful server language, allowing you to manage multiple tasks. Depending on whether you use WordPress, Woocommerce, or you add plugins or scripts, your site will require more or less memory.
When WordPress reaches the memory limit for PHP, it tries to allocate a little more. But when this is no longer possible, the fatal error of this article is displayed.
What can be done to solve this problem?
Depending on the origin of the problem, there are several possible solutions:
- Increase the limit of memory usable for WordPress: it is necessary for that to open the file wp-config.php and define the maximum desired:
define( 'WP_MEMORY_LIMIT', '96M' )(example)
- Check with your hosting provider to see if they can give you more memory or make the necessary adjustment.
- Test your connection with mysqli :
$mysqli_connection = new MySQLi('host', 'user', 'password', 'database_name');
- Edit the php.ini file to increase the memory for all applications:
memory_limit = 256M
- (not recommended) Increase memory via the .htaccess file:
php_value memory_limit 256M
For the amount of memory to be defined, you must be able to estimate your needs. A Woocommerce site will generally consume more memory than a simple WordPress site. Then, depending on the plugins used, the amount of memory required may increase.
Finally, if you find that the amount of memory required for the proper functioning of your site is too large, ask yourself if you would not have a script or a plugin too greedy. Because in addition to causing you this type of problem, your WordPress site can be slowed down or cause other problems.
Finally, do not forget to keep your site up to date, both on the technologies used and on WordPress and its plugins.
Still stuck ? You can contact an expert.