Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Robstar's avatar
Level 50

Forge Scheduler

Randomly out of interest, what are some cron / schedule scripts you have running on your Forge servers (omitting the default Forge scripts)?

0 likes
4 replies
tisuchi's avatar

@robstar Sorry, but I may not get your question correctly!

I used to run all of my scheduled jobs for all of my Laravel projects.

Snapey's avatar

Use forge scheduler to run the Laravel scheduler. Thats all.

Robstar's avatar
Level 50

@Snapey Yep lol :) I'm mainly asking out of interest some common common things people do. Appears as Lary AI answered me.

LaryAI's avatar
Level 58

Certainly! Here are some common cron/schedule scripts that you might find useful to run on your Forge servers, beyond the default Forge scripts:

  1. Database Backups: Regularly back up your database to ensure you have recent copies in case of data loss.
# Backup the database every day at 2 AM
0 2 * * * /usr/bin/mysqldump -u yourusername -pyourpassword yourdatabase | gzip > /path/to/backup/yourdatabase_$(date +\%F).sql.gz
  1. Log Rotation: Rotate and compress logs to prevent them from consuming too much disk space.
# Rotate logs every week
0 0 * * 0 /usr/sbin/logrotate /etc/logrotate.conf
  1. Cache Clearing: Clear application cache periodically to ensure the app runs smoothly.
# Clear Laravel cache every day at midnight
0 0 * * * cd /path/to/your/laravel/app && php artisan cache:clear
  1. Email Reports: Send out daily or weekly email reports.
# Send daily email reports at 6 AM
0 6 * * * cd /path/to/your/laravel/app && php artisan email:send-daily-reports
  1. Security Updates: Automatically update packages to ensure your server is secure.
# Update packages every day at 3 AM
0 3 * * * /usr/bin/apt-get update && /usr/bin/apt-get upgrade -y
  1. Cleanup Old Files: Remove old files from a directory to free up space.
# Delete files older than 30 days from a specific directory
0 4 * * * find /path/to/your/directory/* -mtime +30 -exec rm {} \;
  1. Custom Laravel Commands: Run custom Laravel commands that you have defined in your application.
# Run a custom Laravel command every hour
0 * * * * cd /path/to/your/laravel/app && php artisan your:custom-command

These are just a few examples, and you can customize them based on your specific needs. Make sure to test your cron jobs to ensure they work as expected and monitor their execution to catch any potential issues early.

1 like

Please or to participate in this conversation.