Cron Expression – Schedule Task Every 23 Hours

cron

I want to run a script every 23 hours.
following syntax tried but its not working.
is it right syntax for 23 hours:

<cron_expr>0 0,23,46,69,92,115 * * *</cron_expr>

Best Answer

You could do every 24 hours like this, every 23 hours would be a little trickier.

<cron_expr>0 23 * * *</cron_expr>

Technically the syntax for every something somethings would be */something, so */23 in your case.

Ie. If you wanted a cron to run every 6 hours, exactly on the hour, it would be,

<cron_expr>0 */6 * * *</cron_expr>

But this expression is only going to be valid for values under 12, as the cron's interpretation of 'every' resets each day.

So for every 23 hours, on the hour, you would be best executing it every hour like so, and doing a modulus of 23 within your script itself.

<cron_expr>0 * * * *</cron_expr>

Then in the method being executed, place this at the start,

$time = time();
if (((($time - ($time % 3600))/3600) % 23) != 0)
  return;
Related Topic