1

My question comes from an observation that I made while seeing an every minute cronjob running like that:

12:00:15 (cron started)
12:01:20 (cron started)
12:02:02 (cron started)
.
.
.

As it seems the cron doesn't run every minute (every 60 seconds). That cron actually runs a php script that does a mysql query that selects and updates the database. It completes in less than 2 seconds.

A cronjob scheduled for every minute is supposed to run on the start of the minute (12:00:00) or it would run on any other particular second of that minute?

Has the load of the system anything to do with that? Is there any way to make sure that a cron starts at the very beginning of a minute?

sotoz
  • 113

1 Answers1

3

What you observe doesn't surprise me at all, cron is not precise to the second. You can trust* it to run the job within the minute you programmed it to run, but you shouldn't really rely on more precision.

If you need your job to start at a precise moment, you should start it earlier and wait inside the script for that moment to arrive. And since 1 minute is the smallest interval supported by cron, I'd think about different options out there to start it (e.g. a Python script).

(*) see the comment below

  • 2
    Nothing will guarantee starting instant, as the system could be too busy at the moment to go around to run your program for an indeterminate amount of time (or even be turned off ;-). – vonbrand Oct 20 '15 at 19:15