Performance
Laravel 8
Laravel 9
Laravel 10
Laravel 11
Laravel 12
Maximum Execution Time Exceeded in Laravel - Fix
This error occurs when a PHP script takes longer than the allowed execution time limit to complete.
The Error
Error Message
Maximum execution time exceeded
Common Causes
- 1 Long-running database queries
- 2 Processing large files synchronously
- 3 External API calls timing out
- 4 Inefficient loops or algorithms
- 5 Not using queues for heavy tasks
Solutions
1
Increase timeout for specific operations
PHP
// Temporarily increase for this script
set_time_limit(300); // 5 minutes
// Or use ini_set
ini_set('max_execution_time', 300);
2
Use queues for long-running tasks
PHP
// Instead of processing synchronously
ProcessLargeFile::dispatch($file);
// Create a job
class ProcessLargeFile implements ShouldQueue
{
public function handle()
{
// Long-running task here
}
}
3
Optimize database queries
PHP
// Add indexes to frequently queried columns
$table->index('status');
$table->index(['user_id', 'created_at']);
// Use select to limit columns
User::select('id', 'name', 'email')->get();
4
Set HTTP client timeout
PHP
// Set timeout for external API calls
Http::timeout(30)->get('https://api.example.com/data');
// With retry logic
Http::retry(3, 100)->get('https://api.example.com/data');
Need Help With Your Laravel Project?
I specialize in building custom Laravel applications, process automation, and SaaS development. Whether you need to eliminate repetitive tasks or build something from scratch, let's discuss your project.
About Hafiz
Senior Full Stack Developer. I build production software with Laravel, Filament, Vue, and AI integrations, and write about the real decisions behind shipping it.
Get in touch →