# Illuminate\Queue\MaxAttemptsExceededException: App\Jobs\ProcessOrder has been attempted too many times or run too long. The job may have previously timed out.

- **ID:** `php/laravel-queue-worker-memory-leak`
- **Domain:** php
- **Category:** resource_error
- **Verification:** ai_generated
- **Fix Rate:** 78%

## Root Cause

A queue worker process exceeded the allowed memory limit (memory_limit) or the job's timeout (retry_after or --timeout), causing the job to be released and retried until it reaches the maximum attempts threshold.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Laravel 10 | active | — | — |
| Laravel 11 | active | — | — |
| PHP 8.1 | active | — | — |
| PHP 8.2 | active | — | — |

## Workarounds

1. **Increase PHP's memory_limit in php.ini or via ini_set() for the queue worker: memory_limit = 512M. Then restart the worker: php artisan queue:restart.** (70% success)
   ```
   Increase PHP's memory_limit in php.ini or via ini_set() for the queue worker: memory_limit = 512M. Then restart the worker: php artisan queue:restart.
   ```
2. **Add explicit garbage collection in the job's handle() method: unset($largeVariable); gc_collect_cycles(); Also ensure no circular references exist.** (75% success)
   ```
   Add explicit garbage collection in the job's handle() method: unset($largeVariable); gc_collect_cycles(); Also ensure no circular references exist.
   ```
3. **Use the --max-jobs option to restart the worker after a set number of jobs: php artisan queue:work --max-jobs=100. This prevents memory accumulation.** (85% success)
   ```
   Use the --max-jobs option to restart the worker after a set number of jobs: php artisan queue:work --max-jobs=100. This prevents memory accumulation.
   ```

## Dead Ends

- **** — This only delays the problem; the underlying memory leak or timeout issue still exists, and the job will eventually fail again or consume excessive resources. (60% fail)
- **** — Disabling timeouts can cause workers to hang indefinitely, leading to resource starvation and blocking other jobs. (70% fail)
- **** — Restarting resets the worker state but does not fix the memory leak; the error will reoccur after enough jobs are processed. (80% fail)
