UnderHost
Knowledgebase Docs

PHP max execution time: increase for long scripts

Increase PHP max_execution_time limit for long-running scripts, imports, or batch processing.

On this page

PHP's max_execution_time limits how long a script can run (default 30 seconds). If a script takes longer, PHP kills it and displays "Maximum execution time exceeded" error.

Default limits by environment

  • Shared hosting: Usually 30 seconds (cannot change)
  • Cloud VPS: Usually 300 seconds (can increase)
  • Dedicated servers: Often 300+ seconds (full control)

How to increase max execution time

Method 1: .htaccess (shared hosting)

php_value max_execution_time 300  # 5 minutes

Method 2: wp-config.php (WordPress)

define('WP_MEMORY_LIMIT', '256M');
set_time_limit(300);  # 5 minutes

Method 3: php.ini (VPS/Dedicated)

max_execution_time = 300  # 5 minutes

Then restart PHP: sudo systemctl restart php-fpm

Per-script timeout override

Inside a specific PHP file, increase timeout for just that script:

<?php
set_time_limit(600);  // 10 minutes for this script only
// rest of your code
?>
Long timeouts aren't a cure-all

If a script regularly times out at 30 seconds, increasing to 300 seconds just delays the problem. Optimize the script itself: use database indexes, cache results, process in smaller batches, or use a background job queue.

Related: Timeout errors | Memory limit errors

Was this article helpful?

Still troubleshooting?

Use UnderHost tools for quick checks, or open a support ticket when the issue needs account or server access.

Related articles

Back to Troubleshooting