What Is a Cron Job in cPanel, and How Do You Set One Up for WordPress?
Jobs such as backups, newsletter sends, stock syncs or publishing scheduled posts should run by themselves at set intervals. On Linux servers, cron does this. The Advanced › Cron Jobs tool in cPanel lets you add scheduled tasks without writing code.
Reading the schedule
Each cron job is defined by a five-field schedule:
| Field | Meaning | Example |
|---|---|---|
| 1 | Minute (0–59) | */15 = every 15 minutes |
| 2 | Hour (0–23) | 3 = at 03:00 |
| 3 | Day of month (1–31) | 1 = on the 1st |
| 4 | Month (1–12) | * = every month |
| 5 | Day of week (0–6, 0 = Sunday) | 1 = Monday |
For example, 30 2 * * * runs every day at 02:30, and */15 * * * * runs every 15 minutes. Remember which time zone the server clock uses; the Cron Jobs screen usually shows the server's current time.
WordPress's wp-cron system
WordPress doesn't use a real cron for scheduled tasks. It runs them through wp-cron.php, triggered when a visitor arrives. That has two weaknesses:
- On low-traffic sites, tasks run late; a scheduled post may not publish on time.
- On busy sites, it can be triggered far more often than needed and create unnecessary load.
Replacing wp-cron with a real cron
- In
wp-config.php, add this line before/* That's all, stop editing! */:define( 'DISABLE_WP_CRON', true ); - Open Cron Jobs in cPanel and choose Once Per Fifteen Minutes from the "Common Settings" list.
- In the command field, enter this command with your own domain:
curl -s https://example.com/wp-cron.php?doing_wp_cron >/dev/null 2>&1 - Click Add New Cron Job.
The >/dev/null 2>&1 at the end stops an email being sent on every run. When you first set it up, removing that part for a while and reading the cron emails is an easy way to confirm the job runs without errors.
Things to watch
- Don't run jobs more often than needed. A heavy job running every minute keeps pushing your account's CPU limit. See CPU, RAM and I/O limits.
- Don't add two jobs that do the same thing; compare plugins' own cron suggestions with the job you added.
- If a job that runs a script directly fails with "permission denied", see the file permissions guide; don't set the permission to 777.
- Delete old jobs you no longer use. A removed plugin's job can keep calling a missing file and producing errors.
If the Cron Jobs screen doesn't appear on your account, or you can't work out why a job isn't running, open a support ticket.
评论0
暂无评论
成为第一个分享想法的人。
请登录或注册后发表评论。