I need to set some laravel scheduler on hostinger. How to set this ? My commands are located inside app/console/commands/realtime.php file. Should I include this file path in command to run box in hostinger or something else ?
To set up a Cron Job, open Websites → Manage, search for Cron Jobs on the sidebar and click on it:
Choose type as Php:
In the field "Command to run", change the path to your project path.
This should be something like:
/usr/bin/php /home/u1XXXXXXX/artisan schedule:run
Select these options to run tasks on every minute:
And lastly you should schedule the command to run on the app/Console/Kernel.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\DB;
use Commands\RealTime;
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*/
protected function schedule(Schedule $schedule): void
{
$schedule->command(RealTime::class)->daily();
}
}
Instead of using the daily
schedule you can choose from available methods for different type of schedules, here is the link.
Refer to the task scheduling documentation on Laravel's official documentation
There is an article on Hostinger you can refer to: https://support.hostinger.com/en/articles/1583465-how-to-set-up-a-cron-job-at-hostinger