Cron job runs twice, but only every third time

Hello,
I have set up a cron job which inserts one row of data to the database.
It is scheduled to run every 20 minutes, so there should be 3 entries per hour.
The cron job is running fine, however, when I check the timestamps in the database, they look pretty much like this:
17:00
17:01
17:20
17:40
18:00
18:01
18:20
18:40
19:00
19:01
etc…
Basically the cron job is run twice every third time.
There are no repeat conditions in the script, nothing like this. If I run it manually, there is just one entry.
I can’t figure out why it runs at the whole hour and then one minute later again, and then in 19 minutes, when, according to how it is set up, it should only run once every 20 minutes.
If every execution created duplicate entries, I would understand, I would check the code. But the code that writes to the database is really simple, just one line of SQL INSERT command, no conditions, no repeating… and it does not do this the other two times during the hour!
Does anyone have any explanation? I googled a lot, but I am out of ideas.
Just out of curiosity, I have copied the same file (only changed the table name, so that it doesn’t write to the same table and I can compare the difference) and set it to run every 1 hour or every 2 hours. Those were both good, they were executed just when they should. Once I change it to once every 20 minutes, there is this extra phantom execution.
Thanks

it’s not possible to specify an exact time for the cron jobs. The reason for that is that people tend to set up all their cron jobs at midnight or at the whole hour, which would create big peaks in server load at those times. With just the intervals, we can schedule the cron jobs ourselves to make sure websites won’t suffer because of them

Would you please be so kind and actually read what I wrote?
I know I can’t set specific times, only intervals, I am fine with that, I did not mention that.
My issue is completely different.

I took the time to research, so I am very well aware of how cron jobs can be scheduled with the free hosting.
I am saddened to be treated with a canned response - moreover, one which is actually not even related to my problem!

This is very interesting. I don’t see so many questions about the cron system, and I haven’t seen this problem before either.

But, judging by the symptoms, it looks like there might be an issue with the cron job scheduling. I’ll have to dig into this to figure out what’s going on.

OK, I did some digging, and I think I figured out what’s going on.

On my first test, I was able to reproduce the symptoms you described. Like you, I set up a cron job to run every 5 minutes, with the Hour field set to blank. This caused the cron job to triggered roughly every 5 minutes, as well as another time at the whole hour.

However, when I changed the cron job to run once every 5 minutes and specifically set the Hour setting to 0, the tasks wasn’t triggered again at the whole hour.

So for now, you should not leave the Hour field empty, and instead enter 0 there if you want to trigger it every X minutes.

But I do think that this is confusing and I will try to get this changed.

1 Like

Awesome, thank you for looking into this, for confirming my findings and for the workaround!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.