Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Cron Job in shared host and laravel

Tags:

php

cron

laravel

i want send notification every Minute to my users with laravel framework and shared host ,ssh access not accessible in my host, i'm so sorry for my english

my command

namespace App\Console\Commands;

use App\Classes\NotificationClass;
use Illuminate\Console\Command;

class Checkreserve extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'check:reserve';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'send notification to all user';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $ss=new NotificationClass();
        $ss->sendNotification();
        $this->info('sende to all');
    }
}

my kernel class

namespace App\Console;

use App\Console\Commands\Checkreserve;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * The Artisan commands provided by your application.
     *
     * @var array
     */
    protected $commands = [
        // Commands\Inspire::class,
        Commands\Checkreserve::class,
    ];

    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('inspire')
        //          ->hourly();
        $schedule->command('Checkreserve')->everyMinute();
    }
}

and my cron job

enter image description here

like image 354
EhSAn Avatar asked Oct 26 '25 23:10

EhSAn


1 Answers

Change your command to run the artisan schedule:run. Note that there is a space after php and the path, this tells the cron job to execute the php script which is the artisan file.

php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1

Change your scheduler to

$schedule->command('check:reserve')->everyMinute();
like image 128
Sandeesh Avatar answered Oct 29 '25 14:10

Sandeesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!