Back to Error Center
Maximum execution time exceeded
Error Message
Fatal error: Maximum execution time of 30 seconds exceeded
Cause
A script ran longer than the PHP configured time limit. Common with large data processing, infinite loops, or slow external API calls.
Solution
Increase the time limit temporarily with set_time_limit(). Better yet, optimize the code, use queues for long tasks, or process data in chunks.
Code Example
Fix
// Increase time limit (temporary fix)
set_time_limit(300); // 5 minutes
// Better: use chunking for large datasets
Post::chunk(100, function ($posts) {
foreach ($posts as $post) {
// Process each chunk
$this->processPost($post);
}
});
// Best: use queues for heavy processing
ProcessLargeDatasetJob::dispatch()->onQueue('long-running');
Debugging Steps
- Identify which part of the code is slow
- Check for infinite loops
- Profile database queries for N+1 issues
- Check external API call timeouts
- Monitor memory usage
Prevention
Use chunking for large datasets. Offload heavy work to queues. Set appropriate timeouts for external calls. Profile code regularly.