1

I've read the relevant part of the docs and various guides, but I'm unclear as to whether Laravel requires the the cron to be run every minute, or whether it's OK to run less often, i.e. hourly, daily, weekly, etc, without causing issues?

In my case I need a script to run monthly; at the end of each month. It has to run at UTC-12 hours (i.e. the time at which the given calendar month will cease to exist everywhere on earth). Do I really need to run the cron job every minute for this, or does it suffice to run every hour? I would assume running it every hour will be fine without causing issues, but I'd like to confirm this.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Inigo
  • 8,110
  • 18
  • 62
  • 110
  • Using Laravel's scheduler seems to be a solution for a problem you don't have. It handles multiple tasks on different schedules down to a per-minute granularity. If you only have one task to run once a month you might as well just schedule that in cron directly yourself. – jonrsharpe Dec 12 '20 at 14:29
  • OK, fair comment (although I'd still appreciate an actual answer to question, out of curiosity if nothing else). I assume if I set my cron to run hourly then Laravel would respond by running tasks I've scheduled as e.g. `->everyMinute();` once, on the hour, when my cron runs... ‍♂️ – Inigo Dec 12 '20 at 14:34
  • Regarding your suggestion, I'd still like to use Laravel to run the task though. Where would I point the script in that case? – Inigo Dec 12 '20 at 14:35
  • 3
    **TL;DR**: it's not *required* as such, if you run it at less than the recommended frequency and it happens not to run in the minute when your task is scheduled to run your task **will not** be run. And I don't know how to run a task directly, sorry; I've only done a few months of Laravel/PHP and that was maybe a year ago! – jonrsharpe Dec 12 '20 at 14:45
  • @jonrsharpe Thanks, missed that one; it *does* answer my question, nice one :) I guess I'll just set the cron to run every minute like I'm told. It's not like I'm really saving more than a neglible amount of server power doing otherwise... I just wondered. – Inigo Dec 12 '20 at 15:03

1 Answers1

-2

Cron can be started at any time. You can "play" with Cron at this site. If I understand the question correctly, the solution you need: 0 0 1 * *

This is a run at the beginning of each month. This is necessary because the Cron does not know when there are 31 days in a month and when there are 30 or less.

Or you could do something like this: 59 23 28-31 * *, but then the Cron will be triggered every month from the 28th to the 31st.

Yuriy Vorobyov
  • 755
  • 4
  • 8
  • 2
    Hi, sorry, no, you haven't understood my question properly. I know how to schedule cron jobs on the server. I'm asking specifically about how Laravel responds to crons set less frequently than 1 minute. – Inigo Dec 12 '20 at 14:39