Setting up cron jobs (scheduled tasks).

Run a script every few minutes, hourly or daily: how to add a cron job, test it with Run now, and get its output by email.

2 DƏQ OXUMA

Cron runs a command on a schedule: a WordPress cron, a Laravel scheduler, a backup script, a cleanup task.

Where it is

Your project → Website → Cron jobs (or search «cron»).

Adding a job

  1. Click Add a job.
  2. When — pick a schedule: every minute, every N minutes, every hour, every day at a time, weekdays, a day of every month — or write your own cron expression.
  3. Command — what to run, for example:
cd ~/public_html && php artisan schedule:run
/usr/local/bin/php ~/public_html/wp-cron.php
  1. Click Save.

The job runs as your hosting account, from your home folder. Use full paths or cd first.

Testing it

Run now runs the job at once and shows its output and exit code (0 = fine). A run is stopped after a minute — long tasks belong in the schedule, not in Run now.

Output by email

Email the output sets one address for all jobs of the website: whatever a job prints is mailed there. Jobs that print nothing send nothing. To keep one job quiet, add > /dev/null 2>&1 to its command.

Turning a job off

The switch next to a job turns it off without deleting it («Job turned off — it stays here»). Delete removes it.

WordPress: replace wp-cron with a real cron

WordPress runs its scheduled tasks on visits, which is slow on busy sites and unreliable on quiet ones. Add to wp-config.php:

define('DISABLE_WP_CRON', true);

and add a job every 5 minutes:

cd ~/public_html && /usr/local/bin/php wp-cron.php > /dev/null 2>&1

Good practice

  • Don't run heavy jobs every minute; every 5–15 minutes is plenty for most tasks.
  • Make scripts safe to run twice (a lock file, or checking whether the previous run finished).
  • Log to a file when you need history: >> ~/logs/job.log 2>&1.

Daha sualınız varmı?

Canlı dəstəklə əlaqə saxlayın — günün istənilən vaxtı 3 dəqiqədən az median cavab müddəti.

Dəstəklə əlaqə