Laravel 5.1.x数据库队列任务未执行问题排查求助
Hey Ben, let's dig into why your production queue is stacking up even though you've got the process running in Forge. Since your test site works fine, the issue is likely tied to production-specific config, code, or process state—here's what to check next:
1. Verify Queue Process Environment & Configuration
- Double-check the environment variables for your Forge daemon: Is the queue process loading the correct production
.envfile? Sometimes after deploying, the daemon might still be using old config values (like wrong Redis/database credentials, or a mismatchedQUEUE_CONNECTION). Compare the daemon command in Forge (e.g.,php artisan queue:work redis --queue=default) to your test site's setup and your production.envsettings. - Test the queue driver connection: If using Redis, run
redis-cli pingon the server to confirm connectivity. For database-driven queues, check that thejobstable has pending tasks, and that the queue process has permission to access the production DB. Runphp artisan queue:work --oncemanually—it'll attempt to process one task and spit out any immediate errors.
2. Check for Code Compatibility Issues
- Audit your recent deployment: Did you add new job classes or modify existing task logic? Make sure all production dependencies are installed with
composer install --no-dev—sometimes test-specific packages are missing in production. Also, runcomposer dump-autoloadto refresh autoloading, in case job class paths or namespaces changed. - Review failure logs: Check Laravel's
storage/logs/laravel.logor the Forge daemon logs for error messages. Uncaught exceptions in jobs can cause processes to hang or tasks to retry repeatedly, leading to a backlog. If you've enabled failed job tracking, look at thefailed_jobstable for clues about which tasks are failing.
3. Confirm Queue Process Health & Server Resources
- Ensure the queue process is actually running: Daemons can sometimes crash or get stuck without showing as "stopped" in Forge. SSH into the server and run
ps aux | grep queue:workto see active processes—check the start time to confirm it's running post-deployment. If it's an old process, restart the daemon in Forge. - Check server resource limits: Is the production server low on CPU, memory, or disk space? Queue processes need adequate resources to run—memory exhaustion, for example, can crash the worker. Use
topto monitor CPU/memory usage, anddf -hto check disk space. If using Redis, verify it hasn't hit its memory limit (which would block task processing).
4. Validate Queue Names & Priority Settings
- Match queue names between jobs and workers: If your tasks are dispatched to a specific queue (e.g.,
dispatch(new SendEmail)->onQueue('emails')), make sure your Forge daemon is listening to that queue with--queue=emails,default(order matters for priority). If the worker only listens todefault, tasks in other queues will pile up. - Check retry delays and limits: If jobs keep failing, Laravel will retry them based on
QUEUE_RETRY_AFTERin.envand$tries/$maxExceptionsin your job classes. Excessive delays can make it look like tasks aren't being processed—adjust these settings if needed, or manually delete stuck failed jobs to clear the backlog.
内容的提问来源于stack exchange,提问作者Ben
相关产品推荐
相关产品推荐

