Cron + queue

CartUser uses Laravel's scheduler to run background tasks (expire coupons, send emails, process subscriptions). One cron entry handles everything.

Cron setup

cPanel / Plesk

  1. Log in to cPanel.
  2. Go to Cron Jobs.
  3. Set frequency to Every Minute (or * * * * *).
  4. Command:
    cd /home/user/public_html/kode && php artisan schedule:run >> /dev/null 2>&1
    Replace path with your actual install path.
  5. Save.

Linux server (SSH)

crontab -e

Add this line:

* * * * * cd /home/user/public_html/kode && php artisan schedule:run >> /dev/null 2>&1

Windows (Laragon dev)

Open Task Scheduler โ†’ create basic task โ†’ trigger every 1 minute โ†’ action:

php D:\laragon\www\cartuser\kode\artisan schedule:run

What runs on schedule

TaskFrequencyPurpose
Expire couponsDailyMark expired coupons inactive
Expire reward pointsDailyMark pending points expired
Process recurring subscriptionsDailyCharge sellers, renew/cancel plans
Clean old sessionsHourlyGarbage collection
Send queued emailsEvery minuteOrder confirmations, etc.
Send queued SMSEvery minuteOTPs, order alerts
Refresh exchange ratesDailyMulti-currency price conversion
Auto-cancel unpaid ordersHourlyFree up reserved stock

Verify cron is running

cd /home/user/public_html/kode
php artisan schedule:list

Shows all scheduled tasks + next run time.

Queue worker (optional but recommended)

For high-volume stores, run a queue worker so emails/SMS don't slow down checkout:

1. Set queue driver

Edit kode/.env:

QUEUE_CONNECTION=database

Run migration:

php artisan queue:table
php artisan migrate

2. Start worker

php artisan queue:work --tries=3 --timeout=120

Keep this running. Use supervisord or systemd for production.

3. Supervisord example

; /etc/supervisor/conf.d/cartuser-worker.conf
[program:cartuser-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/user/public_html/kode/artisan queue:work --tries=3 --timeout=120
autostart=true
autorestart=true
user=www-data
numprocs=2
redirect_stderr=true
stdout_logfile=/var/log/supervisor/cartuser-worker.log

Restart worker after deploy

php artisan queue:restart

Daily backup cron (recommended)

Add second cron entry:

0 3 * * * cd /home/user/public_html/kode && php artisan db:backup >> /dev/null 2>&1

Runs daily at 3 AM โ†’ saves to storage/app/backups/.

Troubleshooting cron

Tasks not running

  1. Verify cron entry exists: crontab -l
  2. Verify command path is correct (find PHP: which php)
  3. Run manually to check: php artisan schedule:run
  4. Check cron log: tail -f /var/log/cron
  5. Check Laravel log: tail -f kode/storage/logs/laravel.log

Emails not sending

  1. Run queue worker manually: php artisan queue:work --once
  2. Check failed jobs: php artisan queue:failed
  3. Verify SMTP credentials in .env
  4. Test mail: php artisan tinker --execute="Mail::raw('test', fn($m) => $m->to('[email protected]')->subject('test'));"