How to change the maximum execution time and memory size allowed for PHP

Posted on In QA

I see this message in the error log of httpd:

PHP Fatal error:  Maximum execution time of 30 seconds exceeded in

and

PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted 

How to change them to a longer and larger value?

To change the allowed maximum memory usage of PHP:

Set

memory_limit = 256M

in /etc/php.ini.

To change the maximum allowed execution time of PHP:

Set

max_execution_time = 300

in /etc/php.ini.

You can also set these values in .htaccess if it is allowed by the server. For example, to set the memory_limit:

php_value memory_limit 256M

You can also set the values in the PHP script:

ini_set('memory_limit', '256M');

Some programs has internal defined variables. For example, WordPress has an configuration variable that can be defined in wp-config.php:

define('WP_MEMORY_LIMIT', '256M');

Leave a Reply

Your email address will not be published. Required fields are marked *