Reputation: 61
I have a laravel project and i create a command to do something. My goal is run the command every minute, So I add the command to the schedule. If in the local server I run
php artisan schedule:run It´s works but just one time.
So I upload my project for server and create a Cron Job in the CPanel but I have the error
PHP Fatal error: Class 'Illuminate\Console\Command' not found
Command in the Cron Job
/usr/bin/php /path-to-project/app/Console/Commands/Notification.php
I dont understand why i can run the command in the local server but i can´t run in the online server.
Can anyone help me? thx
Upvotes: 0
Views: 1299
Reputation: 87
What does the Kernel look like? It should at least look like this:
protected function schedule(Schedule $schedule) {
$schedule->command('artisanCommandNameHere')->everyMinute();
}
Personally, I would also add ->withoutOverlapping()
at the end as well to prevent simultaneous executions.
These docs should help you: https://laravel.com/docs/5.8/scheduling
UPDATE:
I just looked again and realized this issue is different than I thought, given the information provided is correct. First off, why are you not letting the Laravel scheduler handle making the cron job? The whole point of the command was to take out the unnecessary complexity of hand-crafting a cron job. Using the above block for the schedule function, just running php artisan schedule:run
on server up will make the job repeat as specified.
However, if you're dead set on creating the cron job yourself, you're missing the artisan portion of your command. You need to add it between php and filename, like so:
usr/bin/php /path-to-project/artisan /path-to-project/app/Console/Commands/Notification.php
Artisan is its own Symfony based CLI, and the commands in Laravel are built to run through it, not to be run as basic php files.
Upvotes: 0