Maximum Execution Time Exceeded

Fatal error: Maximum execution time of 30 seconds exceeded

Quick Answer

Your script ran longer than the configured time limit. This usually indicates an infinite loop, a slow external API call, or a heavy database query. Optimize the slow operation or increase the time limit.

Why This Happens

PHP enforces a maximum execution time per script defined by max_execution_time in php.ini, defaulting to 30 seconds. When this limit is reached, PHP kills the script. This protects the server from runaway scripts but can also trigger on legitimately long-running operations.

The Problem

// Infinite loop due to wrong condition
$i = 0;
while ($i < 100) {
    echo $i;
    // Forgot to increment $i
}

The Fix

$i = 0;
while ($i < 100) {
    echo $i;
    $i++;
}

Step-by-Step Fix

  1. 1

    Find the slow code

    Check the line number in the error. Look for infinite loops, missing loop increments, slow database queries, or external API calls that hang.

  2. 2

    Optimize the operation

    Add proper loop termination, add database indexes, paginate large queries, or add timeouts to external HTTP calls.

  3. 3

    Increase the limit for legitimate tasks

    For CLI scripts or long-running tasks, use set_time_limit(0) or increase max_execution_time in php.ini.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free