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. 1 Long-running database queries
  2. 2 Processing large files synchronously
  3. 3 External API calls timing out
  4. 4 Inefficient loops or algorithms
  5. 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.

Currently available for 2-3 new projects

Hafiz Riaz

About Hafiz

Full Stack Developer from Italy. I build web applications with Laravel and Vue.js, and automate business processes. Creator of ReplyGenius, StudyLab, and other SaaS products.

View Portfolio

Related Errors