PHP Max Execution Time

Home » Documentation » 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.

Modifying Max Execution Time

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');

Common Use-Cases

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

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.