Call Schedule via routes.php


I just on my cronjobs actually called as a cron. But my host does not allow the addition of a cronjobs internally, I have to setup an URL which is called.

So basically I setup the routes.php as written within the documentation:

namespace My\Plugin

use Illuminate\Support\Facades\Artisan;
use Route;

Route::get('/crons', function () {

And well it works well if I call the /crons url.

However, I defined a schedule within the Plugin.php and I wonder if I could call this, too, instead of redefining everything within the routes.php file.

Thanks for the help :slight_smile:

The problem with calling this via a route is that it must be called reliably every minute.

For example, if the schedule is to run at 11:50pm, and it is called only at 11:49 pm and 11:51pm, then the schedule will not run.

Interesting, this was a question which I had on top of my head anyways:

How exact does this work?

I mean:

If the cron should run on 11:50pm but for technical reasons there’s a delay and it’s 11:50:03 - is this to late already, or are the seconds ignored?

The crontable is designed to fire once a minute only.

When I checked the code (years ago), seconds did not matter, just the hour and minutes. This would mean that if you ran it twice in the same minute, the same schedule would run twice.

This logic may have changed in newer Laravel versions, but I doubt it.

1 Like