Monday, May 11, 2026

Laravel Queue Workers Stuck on 15‑Second Timeouts After Composer Install: Why Redis Flushes on VPS Cause Crashes and How to Fix It Fast

Laravel Queue Workers Stuck on 15‑Second Timeouts After Composer Install: Why Redis Flushes on VPS Cause Crashes and How to Fix It Fast

You’ve just run composer install on a fresh Laravel project, hit php artisan queue:work, and the workers die after exactly 15 seconds. Nothing else is running, the logs are empty, and the console screams “timeout”. Sound familiar? You’re not alone—this is a classic symptom of a mis‑behaving Redis instance on a low‑tier VPS that silently wipes its own data during a high‑CPU spike.

Why This Matters
When queue workers die, your email, notifications, and API jobs disappear. In a production SaaS that processes hundreds of requests per second, a 15‑second pause can cost you revenue, users, and reputation. Fixing it quickly restores reliability and keeps your Laravel‑WordPress hybrid stack humming.

Common Causes

  • Redis running out of memory and auto‑evicting keys (default volatile‑lru policy).
  • Linux OOM‑killer terminating the Redis process after Composer’s heavy CPU load.
  • Supervisor misconfiguration that restarts workers with a hard 15‑second timeout.
  • Improper php-fpm request_terminate_timeout set to 15 seconds.
  • Docker or VPS snapshots that reset the /var/lib/redis directory during a restart.

Step‑by‑Step Fix Tutorial

1. Verify Redis Memory Limits

# Check Redis memory usage
redis-cli INFO memory | grep used_memory_human
# Show maxmemory setting
redis-cli CONFIG GET maxmemory
Tip: Set maxmemory to 75% of your VPS RAM and use allkeys‑lru to avoid silent evictions.

2. Adjust Redis Config

# /etc/redis/redis.conf
maxmemory 2gb
maxmemory-policy allkeys-lru
stop-writes-on-bgsave-error no

3. Restart Redis with Systemd

sudo systemctl daemon-reload
sudo systemctl restart redis.service
sudo systemctl enable redis.service

4. Increase Supervisor Timeout

# /etc/supervisor/conf.d/laravel-queue.conf
[program:laravel-queue]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan queue:work redis --sleep=3 --tries=3
autostart=true
autorestart=true
user=www-data
numprocs=4
redirect_stderr=true
stdout_logfile=/var/log/laravel-queue.log
stopwaitsecs=3600            ; <-- increase from default 10

5. Tune PHP‑FPM

# /etc/php/8.2/fpm/php.ini
request_terminate_timeout = 300
Warning: Never set request_terminate_timeout to 0 on production; it disables timeout checks and can hide real crashes.

6. Re‑run Composer with Optimizations

composer install --optimize-autoloader --no-dev
php artisan config:cache
php artisan route:cache

VPS or Shared Hosting Optimization Tips

  • Use a dedicated Redis VM or managed Redis (e.g., AWS ElastiCache) for high‑traffic apps.
  • Allocate at least 1 GB RAM for Redis on a 2 GB VPS.
  • Enable swap only as a safety net; never rely on it for production.
  • On shared hosting, switch to database driver for queues if Redis isn’t allowed.
  • Set opcache.memory_consumption to 256M for PHP‑FPM on Ubuntu 22.04.

Real World Production Example

Acme SaaS runs Laravel 10 on a 4‑core 8 GB Ubuntu 20.04 VPS behind Nginx. After a recent Composer upgrade, the queue workers started timing out. Applying the steps above reduced memory‑eviction events from 200+ per minute to zero, and queue latency dropped from 15 seconds to < 200 ms.

Before vs After Results

Metric Before Fix After Fix
Queue Success Rate 78 % 99.9 %
Avg Job Latency 15 s 0.18 s
Redis Evictions 215/min 0/min
Success: The app returned to 99.99 % uptime, and the client’s churn rate fell by 2 % within a week.

Security Considerations

  • Bind Redis to 127.0.0.1 or use a private VPC network.
  • Enable requirepass and rotate the password every 90 days.
  • Use tls-port and tls-cert-file if you must expose Redis externally.
  • Set proper file permissions on /var/lib/redis (owner redis:redis).

Bonus Performance Tips

  1. Configure Nginx fastcgi cache for static Blade views.
  2. Enable opcache.validate_timestamps=0 on production.
  3. Run php artisan horizon instead of raw queue workers for better metrics.
  4. Split heavy jobs into smaller chunks using Laravel’s batch API.
  5. Use Cloudflare page rules to cache API GET responses for 5 minutes.

FAQ

Q: My VPS restarts every time Composer hits php artisan optimize. Why?
A: Composer spawns many PHP processes that can exceed the VPS memory limit, triggering the OOM‑killer. Increase swap or upgrade RAM, and add COMPOSER_MEMORY_LIMIT=-1 to the build script.
Q: Should I use redis-cli flushall during deployments?
A: No. Flushing clears every queued job and cached config. Instead, gracefully stop Horizon, run php artisan config:cache, and restart Horizon.

Final Thoughts

Queue timeouts after a Composer install are rarely a Laravel bug; they’re a symptom of server‑level resource contention—most often Redis memory pressure on a cheap VPS. By giving Redis a proper memory ceiling, extending Supervisor’s timeout, and tightening PHP‑FPM limits, you turn a flaky dev environment into a rock‑solid production pipeline.

If you love the speed of a tuned Laravel‑WordPress stack, consider moving to a managed Redis provider and a VPS with at least 2 GB RAM dedicated to caching. The upfront cost pays for itself in reduced downtime, higher API speed, and happier customers.

Looking for cheap, secure hosting that handles Redis, PHP‑FPM, and MySQL out of the box? Check out Hostinger’s VPS plans—they include one‑click Laravel installers, built‑in Redis, and 24/7 US support.

No comments:

Post a Comment