What Is a Cron Job?

A cron job is a scheduled task that runs commands or scripts automatically on a server at set times or intervals.

A cron job is a scheduled task that runs automatically on your server at a time or interval you define. It tells the server “run this command every hour” or “run this script every day at 3am” without you having to do anything manually. The name comes from “cron,” the time based job scheduler in Unix and Linux systems. Since almost all web hosting servers run Linux, cron jobs are available on virtually every hosting account.

In this article
  1. What Can You Use Cron Jobs For?
  2. How Cron Syntax Works
  3. How to Set Up a Cron Job in cPanel
  4. Replacing WordPress WP-Cron
  5. Cron Jobs on a VPS
  6. Common Mistakes
  7. Frequently Asked Questions

If you’ve ever wondered how your hosting account sends automated backups, how WordPress checks for plugin updates, or how a contact form sends queued emails in the background, cron jobs are often the mechanism doing the work.

What Can You Use Cron Jobs For?

Anything that needs to happen on a schedule without manual intervention.

Database backups. Schedule a daily or weekly database export so you always have a recent copy. This runs independently of your hosting provider’s backup system and gives you an extra safety net.

Clearing temporary files. WordPress and other applications create cache files and temporary data. A cron job can clean these out at regular intervals to prevent them from eating your storage.

Sending scheduled emails. Newsletters, digest summaries, or queued notification emails can be triggered by a cron job that processes the email queue at set intervals.

Fetching external data. If your site pulls data from an API (exchange rates, stock prices, weather, product feeds), a cron job can fetch and cache that data every hour instead of querying the API on every page load.

Running WordPress cron. WordPress has its own internal scheduling system called WP-Cron. By default, it only runs when someone visits your site. On low traffic sites, that means scheduled tasks (like publishing a post at a specific time) can be delayed. Replacing WP-Cron with a real server cron job ensures tasks run on time regardless of traffic.

Monitoring and alerts. Run a script that checks whether your site is responding and sends you an email if it’s down. Or check disk usage and alert you when storage is running low.

How Cron Syntax Works

A cron job has two parts: the schedule and the command.

The schedule is defined by five fields, each separated by a space:

minute  hour  day-of-month  month  day-of-week  command

Each field accepts specific values:

Field Allowed Values Example
Minute 0 to 59 30 = at the 30th minute
Hour 0 to 23 3 = at 3:00 AM
Day of month 1 to 31 15 = the 15th of the month
Month 1 to 12 6 = June
Day of week 0 to 7 (0 and 7 are Sunday) 1 = Monday

An asterisk (*) means “every.” So * * * * * means every minute of every hour of every day.

Some practical examples:

0 3 * * * runs once a day at 3:00 AM.

0 */6 * * * runs every 6 hours (at midnight, 6am, noon, 6pm).

30 2 * * 1 runs every Monday at 2:30 AM.

0 0 1 * * runs at midnight on the first day of every month.

*/15 * * * * runs every 15 minutes.

If cron syntax looks intimidating, use a free online tool like crontab.guru. You type the five fields and it tells you in plain English what schedule it represents.

How to Set Up a Cron Job in cPanel

Most shared hosting plans include cron job access through cPanel. Here’s how to set one up.

Step 1: Log into cPanel and scroll to the “Advanced” section. Click “Cron Jobs.”

Step 2: Under “Common Settings,” you can pick a preset schedule from a dropdown (once per minute, once per hour, once a day, etc.). For custom schedules, fill in the five fields manually.

Step 3: In the “Command” field, enter the command you want to run. For a PHP script, this looks like:

/usr/local/bin/php /home/yourusername/public_html/script.php

Replace the path with the actual location of your script. The /usr/local/bin/php part tells the server to run the file using PHP. The exact PHP path can vary by host. Check with support or run which php in the terminal if you have SSH access.

Step 4: Click “Add New Cron Job.” The job is saved and will run on the schedule you defined.

cPanel shows all your active cron jobs in a list below the form. You can edit or delete them at any time.

Replacing WordPress WP-Cron

WordPress uses a system called WP-Cron to handle scheduled tasks: publishing future posts, checking for updates, sending email digests, and running plugin scheduled events. The problem is that WP-Cron only triggers when someone loads a page on your site. If nobody visits for an hour, scheduled tasks don’t run for an hour.

Replacing WP-Cron with a real server cron job fixes this. Here’s how.

Step 1: Disable WP-Cron. Add this line to your wp-config.php file, above the line that says “That’s all, stop editing!”:

define('DISABLE_WP_CRON', true);

This stops WordPress from running its internal scheduler on every page load. It also slightly reduces server load because PHP no longer checks the cron queue on every request.

Step 2: Create a server cron job. In cPanel’s Cron Jobs section, add a new job with this command:

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

Set the schedule to every 15 minutes (*/15 * * * *). That’s frequent enough to handle most WordPress tasks without overloading the server.

The >/dev/null 2>&1 part suppresses output so you don’t get an email notification every time the job runs.

Cron Jobs on a VPS

If you’re on a VPS with SSH access, you can manage cron jobs directly from the command line. Type crontab -e to open your cron schedule in a text editor. Add your job on a new line using the same syntax, save, and exit. The job is active immediately.

VPS users have more flexibility because you’re not limited by a control panel interface. You can run system level commands, chain multiple scripts together, pipe output to log files, and schedule tasks at second level precision (with workarounds since cron itself only goes down to minutes).

If your VPS uses Plesk, cron jobs are managed under Tools and Settings > Scheduled Tasks. The interface is similar to cPanel’s.

Common Mistakes

Running jobs too frequently. A cron job that runs every minute and hits the database or makes API calls can overload a shared hosting account. Start with once per hour or once per day and only increase frequency if you genuinely need it.

Wrong file paths. Cron jobs run from the server root, not from your website directory. Always use absolute paths (/home/yourusername/public_html/script.php), not relative paths (script.php). A wrong path means the script silently fails.

Forgetting to suppress output. By default, cron sends the output of every job to your email. If a job runs every 15 minutes and produces output, you’ll get 96 emails per day. Add >/dev/null 2>&1 to the end of your command to suppress this.

Not checking server timezone. Cron uses the server’s timezone, which might not match yours. Check your server’s timezone in cPanel (Server Information) and adjust your schedule accordingly.

Permission issues. The script you’re calling needs to be executable. If it’s a PHP file, make sure the PHP path is correct. If it’s a shell script, make sure the file has execute permissions (chmod +x script.sh).

Frequently Asked Questions

Do all hosting plans support cron jobs?

Most shared hosting plans include cron job access through cPanel. Some budget hosts limit the minimum interval (e.g. no more often than once per 15 minutes) to prevent abuse. VPS and dedicated servers have no restrictions. Check your host’s documentation or ask support if you’re unsure.

Can cron jobs slow down my site?

Only if the job is resource intensive and runs during peak traffic. A cron job that exports a large database runs heavy queries or processes thousands of emails will use CPU and RAM. Schedule heavy jobs during low traffic hours (early morning) to minimise the impact.

What happens if a cron job fails?

It silently fails unless you’ve set up logging or email notifications. If you’re not suppressing output, cron sends error messages to your email. For important jobs (like backups), it’s worth adding error handling to the script and checking logs periodically to make sure everything is running as expected.

Is WP-Cron bad?

Not bad, just limited. For sites with consistent traffic, WP-Cron works fine because pages load frequently enough to trigger the scheduler. For low traffic sites or sites where timing matters (publishing posts at exact times, running time sensitive tasks), replacing it with a real server cron job is a simple improvement.

← Back to Web Hosting Glossary