Opent in een nieuw tabblad
Lijn-B Mailflow

Lijn-B Mailflow

Set up a real cron job

Mails on time, every time

Lijn-B Mailflow sends its emails from a queue. A step in a sequence, a scheduled campaign or a “wait until 07:00” is picked up by a small task that should run every minute. For that task to run on time you need a real cron job. This guide explains why, and how to set one up in Plesk, cPanel and DirectAdmin.

Why WP-Cron is not a real cron

WordPress has a built-in scheduler called WP-Cron. Despite the name it is not a real cron. A real cron is a clock on your server: at the set time the task runs, whether anyone is on your site or not. WP-Cron has no clock. It only wakes up when someone opens a page on your website, and then checks whether anything is due.

No visitors, no emails

On a quiet, new or staging site nobody may visit for hours. A mail planned for 07:00 can arrive at 11:30, or when you happen to look at the site yourself.

Cached pages do not count

If a caching plugin or your host serves a page without running WordPress, that visit does not trigger WP-Cron either.

Busy sites pay for it

On a busy site every visit may start the check, which wastes resources and can run the same task twice.

It can be blocked

WP-Cron starts itself with a request from your site to your site. Basic authentication, firewalls, security plugins and some hosts block that request, and then nothing runs, without any error.

For a contact form WP-Cron is usually fine. For email that people expect on time, like a 7-day course that should arrive every morning, it is not solid enough. The fix takes about five minutes. Lijn-B Mailflow also warns you on its dashboard (Mailflow > Overview) when emails are ready but the queue has not run for more than 10 minutes.

What you will do

1. Create a cron job on your hosting that opens wp-cron.php on your site every minute.
2. Check that it works.
3. Switch off WordPress’ own WP-Cron, so the two do not get in each other’s way.

Replace example.com with your own domain everywhere below. Use the address that visitors end up on (https, with or without www, as your site redirects).

The command

Pick one. The first works on almost every host.

1. curl

curl -s "https://example.com/wp-cron.php?doing_wp_cron" > /dev/null 2>&1

2. wget

wget -q -O - "https://example.com/wp-cron.php?doing_wp_cron" > /dev/null 2>&1

3. PHP directly

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

The PHP command runs the file on the server, without a web request. It needs the correct path to PHP and to your site folder; ask your host or look at the other cron examples in your control panel.

Keep the quotes around the address, because the ? has a special meaning on the command line. The part after > /dev/null throws the output away, so your host does not email you every minute.

The timing: every minute

Cron timing is written as five fields: minute, hour, day of month, month, day of week. A star (*) means “every”. So every minute is five stars:

* * * * *

Some control panels want you to type this as one line of text (the “cron style”). Others give you a form with five boxes or a drop-down. In all cases the result is the same: a star in every field, or the preset “Once per minute” if there is one.

If your host does not allow every minute: */5 * * * * is every 5 minutes and */15 * * * * every 15 minutes. Mailflow still works, but mails go out in bigger steps. Then raise Emails per minute (maximum) under Mailflow > Settings, because each run sends at most that number of emails.

Plesk

Plesk offers both a form and “cron style” text.

1. Log in to Plesk. Go to Websites & Domains, find your domain and click Scheduled Tasks. Use the one for your domain, so it runs under the right user.
2. Click Add Task.
3. At Task type choose Fetch URL and enter https://example.com/wp-cron.php?doing_wp_cron. (Or choose Run a command and use the curl line above.)
4. At Run choose Cron style and enter * * * * *.
5. Description: “Lijn-B Mailflow queue”. Under notifications choose Do not notify, so you do not get an email every minute.
6. Click OK.

Labels differ a bit between Plesk versions, but the three things to find are the task type (URL or command), the timing (cron style) and the notification setting.

cPanel

cPanel has a form with a drop-down for common timings.

1. Log in to cPanel and open Cron Jobs (under Advanced).
2. Optional: at Cron Email enter an address if you want mail about the output. Leave it empty to receive nothing.
3. Under Add New Cron Job, at Common Settings, choose Once Per Minute (* * * * *). The five boxes (Minute, Hour, Day, Month, Weekday) fill themselves with a star each.
4. At Command paste the curl line from above.
5. Click Add New Cron Job. It now appears under Current Cron Jobs.

Some cPanel hosts do not allow every minute. If the job is rejected, use Once Per Five Minutes instead.

DirectAdmin

DirectAdmin has a form with five boxes.

1. Log in to DirectAdmin. Under Advanced Features open Cron Jobs.
2. Click Create Cron Job (in the older skin, scroll to the form at the bottom of the page).
3. Fill in a star (*) in each of the five boxes: Minute, Hour, Day of Month, Month and Day of Week. If a box is a drop-down, choose the “every” option (the star).
4. At Command paste the complete curl line from above, starting with curl. DirectAdmin pre-fills this box with your home folder (for example /home/USERNAME/). Replace that text; a folder name alone is not a command.
5. Save with Create. The job appears in the list at the top, with your command in the last column. Check that you can read the full curl line there.

At the top of the page you can set a cron email. Leave it empty, or keep > /dev/null 2>&1 in the command, so you are not mailed every minute.

No cron access at all?

Some hosts do not offer cron jobs. Then use an outside service that opens the address for you every minute, such as cron-job.org (free). Create a job with the address https://example.com/wp-cron.php?doing_wp_cron and the schedule “every minute”. It does the same thing as a cron job on your hosting.

Switch off WP-Cron

Do this after the real cron job works, otherwise nothing runs at all. Open wp-config.php in the main folder of your WordPress site (with the file manager of your hosting or with FTP) and add this line above the line that says That’s all, stop editing!:

define( 'DISABLE_WP_CRON', true );

WordPress then no longer starts the check on every page visit. Your cron job does the work, on time.

Check that it works

Wait two minutes. Open the Lijn-B Mailflow dashboard: the warning about a stalled queue is gone, and the number of emails in the queue goes down when something is ready. Or open https://example.com/wp-cron.php?doing_wp_cron in your browser: a blank white page is correct. Or send a test: sign up with your own address for a sequence and check that the mail arrives within a minute or two.

If it does not work

The command field is empty, or only holds a folder

The most common mistake, and it gives no error: the job runs every minute and does nothing. The timing can be perfectly right (“Every minute”) while the Command box contains only a path such as /home/USERNAME/. Open the job again and make sure the command is the complete line, for example curl -s "https://example.com/wp-cron.php?doing_wp_cron" > /dev/null 2>&1.

Wrong address

Open the address in your browser. If you see an error page or a redirect to a login, the cron job gets that too. Use the final address (https, with or without www).

Password-protected site (staging)

A site behind basic authentication blocks cron too. Use curl -s -u USER:PASSWORD "https://example.com/wp-cron.php?doing_wp_cron" > /dev/null 2>&1, or allow the server’s IP address.

Firewall or security plugin

Allow wp-cron.php on the address of your site. A bot protection service in front of your site (such as Cloudflare) may block curl; allow the server’s IP address or use the PHP command.

curl or wget is missing

Try the other one, or the PHP command.

Still stuck?

With WP-CLI installed, you can use cd /home/USERNAME/public_html && wp cron event run --due-now > /dev/null 2>&1 as the command.

Lijn-B Mailflow

Lijn-B Mailflow is a free WordPress plugin for contacts, lists, sequences and campaigns.

About Lijn-B Mailflow