Skip to content

PHP max execution time

PHP Max Execution Time is a critical configuration directive in web development. It sets the maximum time, in seconds, that a PHP script is allowed to run before it is terminated by the parser. This setting helps prevent poorly written scripts from running indefinitely, which could crash the server.

By default, the max execution time is set to 30 seconds. However, this can vary depending on your server’s configuration. You can check the current setting using the phpinfo() function or by reviewing the php.ini configuration file.

To change the max execution time, you have several options:

  1. php.ini File: Locate the php.ini file and modify the max_execution_time directive.
max_execution_time = 60
  1. .htaccess File: Add the following line to your .htaccess file.
php_value max_execution_time 60
  1. PHP Code: You can also set this within your PHP script using the ini_set function.
ini_set('max_execution_time', '60');

The need to increase max execution time often arises in the following scenarios:

  • Large File Uploads: Uploading large files can take more time than the default setting allows.
  • Database Backups: Creating backups of large databases can exceed the default execution time.
  • Complex Calculations: Scripts performing complex calculations may need more time to complete.

If you encounter the “Maximum execution time exceeded” error, try the following troubleshooting steps:

  1. Verify Changes: Ensure that the changes made to php.ini, .htaccess, or the PHP script are correctly applied.
  2. Server Configuration: Verify that your web server (Apache, Nginx) is reading the correct php.ini file.
  3. Script Optimization: Review your script for possible optimizations to reduce execution time.

Interaction with WP Memory Limit and WP Max Memory Limit

Section titled “Interaction with WP Memory Limit and WP Max Memory Limit”

The PHP Max Execution Time setting interacts with other settings, such as WP Memory Limit and WP Max Memory Limit, in several ways:

  1. Memory Consumption: A script running for a longer time may consume more memory. Therefore, increasing max execution time might require a corresponding increase in memory limits.
  2. WP Memory Limit: This setting defines the maximum amount of memory a WordPress script can use. If a script exceeds this limit, it will terminate, regardless of the max execution time.

By understanding and configuring these settings, you can optimize your WordPress site’s performance and prevent common issues related to script execution time and memory limits.

The related max_input_time directive sets how long PHP may spend reading the request data, such as a form or an upload, before the script starts. Slow uploads and large forms can be cut off when it is too low. You change it the same way as max_execution_time:

max_input_time = 60

The Site health screen shows both settings under Details, as Max execution time and Max input time in the Server panel. In the Reliability area it warns when:

  • PHP max execution time is 20s (with your value): max_execution_time is below 30 seconds. Longer requests such as imports and updates are stopped.
  • PHP max input time is 30s (with your value): max_input_time is below 60 seconds.

A value of 0 or less means no limit and shows as Unlimited; it never counts as too low.