Great question! First, let’s clarify the PSR-1 concern:
PSR-1 is about basic coding standards (file structure, class naming, etc.), not runtime configuration like max_execution_time. Adjusting PHP’s execution time does not violate PSR-1, as it’s not a declaration or side effect in the sense PSR-1 describes.
Best Practice for Long-Running Jobs
You’re correct that setting a high max_execution_time globally is overkill and not ideal. The best approach is to run long-running jobs on dedicated queue workers with their own configuration.
How to Set Up Dedicated Workers in Laravel
Suppose you have a job that needs more time. Here’s how you can handle it:
-
Use a Separate Queue Connection or Queue Name
In your
config/queue.php, you can define a new connection or just use a different queue name. -
Dispatch the Job to a Specific Queue
// Dispatch the job to the 'long-running' queue LongRunningJob::dispatch()->onQueue('long-running'); -
Start a Worker with Custom PHP Settings
You can start a worker for that queue with a higher
max_execution_time:php -d max_execution_time=300 artisan queue:work --queue=long-runningOr, if you use Supervisor to manage workers, your config might look like:
[program:laravel-long-running] process_name=%(program_name)s_%(process_num)02d command=php -d max_execution_time=300 /path/to/artisan queue:work --queue=long-running --sleep=3 --tries=3 autostart=true autorestart=true user=youruser numprocs=1 redirect_stderr=true stdout_logfile=/path/to/your/worker.log -
Keep Your Default Workers Fast
Your default worker can keep the normal
max_execution_timeand process all other jobs.
Summary
- Don’t change sitewide settings just for a few jobs.
- Use dedicated workers (with Supervisor or similar) for jobs that need more time.
- Dispatch those jobs to a specific queue.
This approach is scalable, maintainable, and doesn’t violate any PSR standards.
Let me know if you need a Supervisor config example or more details!