PHP Maximum Execution Time and Out of Memory Errors

Often when clients run WordPress on shared hosting they eventually run into PHP errors like maximum execution time or out of memory errors. This as inevitably you will run into coding errors causing this or the use of plugins or themes that are simply more demanding. Here are the possible solutions to deal with these errors.

Maximum Execution Time Exceeded

To fix PHP maximum execution time errors like:

PHP Fatal error: Maximum execution time of 120 seconds exceeded in /home/[user-name]/public_html/wp-content/plugins/pagefrog/admin/class-pagefrog-instant-articles-parser.php on line 755

you can add the following to your .htaccess:

php_value max_execution_time 300

or by adding this to you PHP ini:

 max_execution_time = 300;

If you run Nginx and need to do these changes  in PHP-FPM you need to edit

/etc/php5/fpm/pool.d/www.conf

and set:

request_terminate_timeout = 300

Out of Memory Errors

The other error you often get using heavier plugins like WooCommerce or Revolution Slider is an error like:

Fatal error: Out of memory (allocated 1827405824) (tried to allocate 88800 bytes)

To deal with this you can add the following to .htaccess:

 php_value memory_limit 128M

and in PHP.ini:

 memory_limit = 128M;

In Nginx you could add:

php_memory_limit: 128M

to /etc/php5/fpm/php-fpm.conf .

Caveats

There are several caveats I want to tell you about:

  • so remember that these values depend on your server’s limitations and that this will be the limit for each concurrent PHP process.
  • all values set can be and should be adjusted to your needs
  • each server setup has different rules: sometimes php.ini cannot be edited, sometimes nothing at all and sometimes these changes have to done from a control panel
Tagged in : Tagged in : ,
Jasper Frumau

Jasper has been working with web frameworks and applications such as Laravel, Magento and his favorite CMS WordPress including Roots Trellis and Sage for more than a decade. He helps customers with web design and online marketing. Services provided are web design, ecommerce, SEO, content marketing. When Jasper is not coding, marketing a website, reading about the web or dreaming the internet of things he plays with his son, travels or run a few blocks.