# Add a Cron Job (Scheduled Task)

https://voligen.com/en/knowledgebase/article/add-cron-job

A cron job is a scheduled task that runs a command automatically at times you choose. It is used for sending newsletters, updating exchange rates, clearing caches or running WordPress's scheduled tasks.

![When the time comes, the command runs by itself.](https://voligen.com/templates/website/Voligen/assets/images/kb/cron-job-ekleme.svg)

## Before you start

- Know the full path to your script. On cPanel accounts the home directory looks like `/home/username`; your username is shown in the side panel of the cPanel home page.
- Run the script once by hand or in the browser to make sure it works without errors.
- Do not schedule tasks more often than needed; every run uses part of your account's CPU and process limits.

## Add a cron job

1. In cPanel, open **Cron Jobs** in the **Advanced** section.
2. Under **Add New Cron Job**, pick a preset from **Common Settings** (for example *Once Per Hour*) or fill in the minute, hour, day, month and weekday fields yourself.
3. Type the command in the **Command** field and click **Add New Cron Job**. The task appears under **Current Cron Jobs** at the bottom, where you can edit or delete it.

![1: Choose the frequency, 2: enter the command, 3: the task appears in the list.](https://voligen.com/templates/website/Voligen/assets/images/kb/cron-job-ekleme-adim.svg)

## Reading the time fields

A cron schedule has five fields: **minute hour day month weekday**. An asterisk (`*`) means "every".

| Expression | Meaning |
| --- | --- |
| `*/15 * * * *` | Every 15 minutes |
| `0 * * * *` | On the hour, every hour |
| `30 3 * * *` | Every day at 03:30 |
| `0 9 * * 1` | Every Monday at 09:00 |
| `0 0 1 * *` | Midnight on the 1st of each month |

Times follow the server's time zone.

## Example commands

### Run a PHP script

```
/usr/local/bin/php /home/username/public_html/task.php >/dev/null 2>&1
```

The PHP path can differ between servers; if the command fails, try plain `php`. The trailing `>/dev/null 2>&1` discards output so you do not get an email on every run.

### Call a URL

```
curl -s https://example.com/cron.php >/dev/null 2>&1
```

## WordPress: replace wp-cron with a real cron job

By default WordPress checks its scheduled tasks on every page visit. On busy sites that adds load; on quiet sites tasks run late. A healthier setup:

1. Add this to `wp-config.php` before the `/* That's all, stop editing! */` line: `define('DISABLE_WP_CRON', true);`
2. Add a cron job in cPanel that runs every 15 minutes: `cd /home/username/public_html && /usr/local/bin/php wp-cron.php >/dev/null 2>&1`

> ****Tip****
> 
> While testing a new task, remove the trailing redirect and enter your address in the **Cron Email** field at the top of the page. The task's output is emailed to you; put the redirect back once it works.

## Troubleshooting

| Symptom | Likely cause | Fix |
| --- | --- | --- |
| Task never runs | Relative file path | Always use the full path starting with `/home/username/...`. |
| "Could not open input file" | Wrong file name or path | Copy the path from the File Manager address bar. |
| An email on every run | Output not redirected | Add `>/dev/null 2>&1` to the end of the command. |
| Site slows down when the task runs | Task too frequent or too heavy | Run it less often, or move it to night hours. |

## Frequently asked questions

### How often can a task run?

The smallest cron unit is one minute. On shared hosting, every-minute tasks can strain resource limits, so we recommend intervals such as 5 or 15 minutes.

### How do I know the task ran?

Have the script write a short log line, or receive the output via Cron Email.

### Can I run Python or other scripts?

Yes, using the full path of an interpreter installed on the server. For jobs that need custom software, [VDS servers](https://voligen.com/ssd-sanal-sunucular-vds-vps) give you more freedom.

### Can I pause a task temporarily?

cPanel has no pause button for cron jobs. Note down the command and schedule, delete the task, and add it again with the same settings when you need it.

If you get stuck, open a ticket from the client area.
