I want to create a cron job for Laravel 5.2
My shared host (on OVH), only allows me to point to the full path of a file, and I am not able to use the recommended Cron entry from Laravel's docs, ie :
* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1
Therefore, I have to call the Artisan command from a .php file, outside of the Laravel framework.
Here is what my public/cron.php
file looks like so far:
<?php
require __DIR__.'/../bootstrap/autoload.php';
use IlluminateSupportFacadesArtisan;
Artisan::call('refresh');
refresh
being my command for regenerating thumbnails inside my app.
When accessing cron.php through my browser (testing on local XAMPP), the following error occurs:
Fatal error: Uncaught RuntimeException: A facade root has not been set. in
C:xampphtdocssitevendorlaravelframeworksrcIlluminateSupportFacadesFacade.php:210
Stack trace:
#0 C:xampphtdocssitepubliccron.php(7): IlluminateSupportFacadesFacade::__callStatic('call', Array)
#1 {main} thrown in C:xampphtdocssitevendorlaravelframeworksrcIlluminateSupportFacadesFacade.php on line 210
I have also tried to boot the app, but it doesn't make any differences
$app = require_once __DIR__.'/../bootstrap/app.php';
$app->boot();
To avoid using the Artisan Facade, I tried calling the underlying Kernel Class directly:
use IlluminateContractsConsoleKernel;
$kernel = new Kernel;
$kernel->call('refresh');
But this returns:
Uncaught Error: Cannot instantiate interface IlluminateContractsConsoleKernel
EDIT: Here is a screenshot of OVH cron interface. The cron task is customized by OVH and only allows to point to the fullpath uri of a file - which file would execute my artisan command-. My question is, what should I put in this file, and should it be a PHP file, or a CMD?
See Question&Answers more detail:
os