Automatically retry a cron job when the server hiccups

A 503 at three in the morning because your host is installing an update – and the shop export is missing for a whole day. In such cases Cronjob.de automatically tries again: after 1, 5 and 15 minutes, each time from another one of our servers. If one of the attempts works, your cron job runs and you get no failure alert.

The most important rule

We only retry what certainly did not run

A newsletter that goes out twice or an import that books everything twice is worse than a missed run. That is why Cronjob.de distinguishes precisely: if the call never reached your script, a second attempt is safe. If the script may already have done its work, we do not retry but alert you as usual.

ResponseRetryWhy
Connection refused, TLS erroryesThe server never accepted the call.
502 Bad Gateway, 503 Service UnavailableyesOverload, restart or maintenance – the script did not run.
Cloudflare 521, 522, 523, 525yesCloudflare could not reach your server.
408, 429yesThe server explicitly asks to try again later.
500 Internal Server ErrorneverYour script ran and crashed – possibly after doing its work.
504, 524, timeoutneverThe script may still be running; a second call would start it twice.
After a redirectneverThe first target may already have carried out the task.
403, 404 and other 4xxneverA second attempt changes nothing – the troubleshooting guide helps here.

How it works

What happens after a hiccup

After 1, 5 and 15 minutes

Per cron job you choose one, two or three more attempts. Short glitches are usually over after a minute, a restart or update after a few minutes.

Alert only at the end

While an attempt is still pending, the failure alert waits. If all fail, you get the alert as usual – by email, Telegram, Slack or Teams.

From another server

Every attempt comes from another one of our servers than the scheduled call. If the problem is the route between us and your server, this often still works.

Visible in the log

You see both runs: the failed one with its error code and the attempt afterwards, marked as “Retry 1”, “2” or “3”.

Only where it makes sense

If the next scheduled run comes before the retry, it is skipped. Per-minute jobs are therefore never retried – nightly and hourly tasks are.

One click per cron job

Switch it on in the cron job form, “Success check” tab, option “Retry on hiccups”. From Plus, at no extra cost.

Tip

Your script can ask for a later attempt itself

Sometimes your script knows best that now is not a good time – for example because the previous run is still working or a service it needs is not answering. If retries are switched on and your script then answers with status 503 before changing anything, we try again later. Important: the 503 has to come before the actual work begins.

<?php
$lock = fopen(__DIR__ . '/export.lock', 'c');
if (!flock($lock, LOCK_EX | LOCK_NB)) {
    http_response_code(503);   // previous run still working: try later
    exit;
}
// ... the actual work ...
echo 'OK';

FAQ

Common questions

Can the retry make my script run twice?
No. We only retry when the call certainly did not reach your script: the server was unreachable, refused the connection or answered with 502, 503 or a Cloudflare error such as 522. After a 500, a timeout or a redirect your script may already have run – then we never retry.
When exactly do the retries happen?
After 1, 5 and 15 minutes – one, two or three attempts depending on your setting. Since a pass on our servers takes up to a minute, an attempt can come one minute later. If your cronjob is due again anyway before that, the retry is skipped.
Do I get a failure alert if the retry works?
No. We only alert you once all attempts have failed. The log still shows both: the failed run and the successful attempt, marked as “Retry 1”.
Does the retry come from the same server?
No, deliberately from another one of our servers. If the hiccup is in the connection between our server and yours, it often works from there. If you allowed our addresses in a firewall, please use the complete list at cronjob.de/ips.txt so the retries get through too.
Is a cronjob that runs every minute retried too?
No, that would be pointless: the next scheduled run comes a minute later anyway. Retrying helps most with tasks that run rarely – hourly, at night or once a day.
Which plan includes retries?
From Plus (€1.49 per month, €17.88 per year), at no extra cost, also on Unlimited and during the first 14 days after signing up. You switch it on per cronjob in the “Success check” tab.

Try it free for 14 days

Every sign-up starts with 14 days of Unlimited – with automatic retries, failure alerts and one-minute intervals. After that, up to five cron jobs keep running for free; retries are available from Plus for €17.88 per year.

Start for free See pricing