appson2
appson2

Reputation: 13

Laravel Create cron job on shared hosting

I started to learnig "Scheduling task" chapter in Laravel docs. On localhost xampp project I created command which delete last inserted row in table

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

/**
 * The console command description.
 *
 * @var string
 */
protected $description = 'Delete task';

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

/**
 * Execute the console command.
 *
 * @return mixed
 */
public function handle()
{

    DB::table('task')->orderBy('id', 'desc')->limit(1)->delete();
    echo 'done';
}

}

Then I added it to Kernel

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

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


}

/**
 * Register the commands for the application.
 *
 * @return void
 */
protected function commands()
{
    $this->load(__DIR__.'/Commands');

    require base_path('routes/console.php');
}

}

Then I created .bat file with php artisan schedule:run command and added it to task manager in windows. Everything worked fine.

Next I uploaded this project to shared server with ssh access and cron jobs feature. I want to use php artisan schedule:run but I receive messsage:No scheduled commands are ready to run.

On the other hand The server has a in-build creator of cron jobs. I can create task. I must just set date and time and fullfill the field translated in English for "command" (see picture below). I have no idea what should I input here. Please help (appson is my domain name).

picture

Upvotes: 1

Views: 1992

Answers (1)

Spholt
Spholt

Reputation: 4012

The cron entry to add can be found in the documentation

https://laravel.com/docs/6.x/scheduling#introduction

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

If you can't access something like crontab, you should just be able to add this entry in your server's "in-build creator of cron jobs"

Upvotes: 2

Related Questions