Operations and security 5 min read Updated
Scheduled jobs that do not fail silently
In short
A scheduled job fails silently unless each run is recorded, a missing run raises an alert and a repeated run does no harm.
A cron job that stops working rarely announces it. The site looks normal, a report stops arriving or a queue fills up, and nobody notices until a customer does. For every job, check whether it ran at all. Google’s SRE Book has a chapter on distributed periodic scheduling that explains why scheduled work becomes hard at scale and what owners should do about it. Apply these points to a small PHP product that runs its jobs from a crontab on one server.
Cron starts a command from five time fields
A crontab entry has five time fields followed by a command. In the system crontab, a username also appears before the command. The crontab manual adds two details that matter for a small team. If MAILTO is set, cron sends mail to that address; otherwise the mail goes to the owner of the crontab. Mail is easy to overlook, so it must never be your only alarm.
The manual also says that jobs scheduled at local times skipped by a daylight saving change are not run. It does not say what happens when the machine is off at a scheduled time, so do not assume that missed runs will be made up later. Treat a missed run as an ordinary event that you must detect.
Lock each run so that runs never overlap
The SRE chapter warns that a cron job may be delayed when resources are unavailable. Poor scheduling can lead to a missed run or to the same job running twice. The chapter states that some jobs must not run more than once. In general it prefers skipping a run to risking a double run.
The chapter does not cover overlapping runs of the same job, so the advice that follows is general practice. Protect each run with a lock: a lock file held by flock, or a row that the run marks at its start and clears at its end. A run that finds the lock already held should exit and record why. A run that starts while the previous one is still working is a common source of duplicated work.
Working on something similar in your own product? A few honest sentences are enough – we read every enquiry and reply by email. Apply with your idea
Design every job so that it can safely repeat
The chapter distinguishes idempotent jobs from jobs that must not run twice. Garbage collection is its example of an idempotent job, because running it again does no harm. A job that sends a newsletter is different, and it must record what it has already done before it does anything else.
Build each job around a known set of records. Mark each record when it is done, so that a job which fails halfway resumes where it stopped instead of starting again from the beginning. When the job calls a third-party service, send an idempotency key with each request if the service supports one, so that a retry cannot repeat the effect.
Log each run and alert on silence
The SRE chapter says that cron job owners can, and should, monitor their jobs. It also suggests that an owner might expose the state of the jobs it manages. It gives no detailed alerting guidance, so the points below are general practice.
For every run, write a start line, an end line, the result and the number of records processed, in a place someone reads. Keep personal data out of those lines, as explained in logging: what to record and how long. Alert when a run fails, and also when a run does not start within its expected window. The second alert matters most, because a silent failure produces no error at all. For the wider approach to alerts, see Monitoring and alerts for a small product.
| Question | Answer a small team should be able to give |
|---|---|
| A second run starts while the first is still working | It does not. A lock stops it, and the refused run is logged |
| A run fails halfway | The next run resumes from the last record marked as done |
| Who learns that a run did not happen | A named person, through an alert that does not depend on the job itself |
| Where to find the output of each run | A log with the job name, start time, end time and result |
A checklist for each scheduled job
Apply this checklist to every job before it goes into the crontab, and again whenever its code changes. If an alert fires, follow incident response for a small team.
- Name the job, its owner and the interval at which it should run.
- Take a lock at the start and release it at the end.
- Make the job safe to repeat, or record what it has already done.
- Log the start, the end and the result where someone reads them.
- Alert on failure, and on a run that does not happen in its window.
- Test the alert once by stopping a copy of the job on purpose, in a test environment.
Common questions
- Why do scheduled jobs fail silently?
- Cron sends mail only to the address in MAILTO or, if it is not set, to the owner of the crontab. A run that never starts produces no output at all, so nothing appears in the log either.
- Should two runs of the same job be allowed to overlap?
- The SRE Book says some jobs must not be launched more than once, and that skipping a launch is generally preferred to a double launch. It does not cover overlapping runs, so a lock is general practice rather than a rule from the chapter.
- How do I know that a run did not happen?
- The SRE Book says cron job owners can and should monitor their jobs. Set an alert for an expected run that is missing, not only for a run that reports an error.
Sources
- Distributed Periodic Scheduling with Cron, Google SRE Book. Accessed 24 November 2026
- crontab(5), man7.org (Linux man-pages). Accessed 24 November 2026
Further reading
-
Monitoring and alerts for a small product
Alert on what users experience, and keep pages for problems that need a person to act now.
-
Storing dates and time zones without surprises
Store moments in UTC, keep the local time and zone for future events, and use immutable PHP date objects with IANA zone names.
-
Backups you can actually restore
A backup counts only once you have restored from it, so follow the 3-2-1 rule, keep one copy disconnected and test restores on a schedule.
Have an idea that should exist? Or a working product that needs more customers, a new website or a complete rework? Bring us anything. Apply with your idea