在共享主机和 laravel 中创建 Cron 作业

EhS*_*SAn 4 php cron laravel

我想使用 Laravel 框架和共享主机每分钟向我的用户发送通知,在我的主机中无法访问 ssh 访问,我对我的英语感到非常抱歉

我的命令

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');
    }
}
Run Code Online (Sandbox Code Playgroud)

我的内核类

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();
    }
}
Run Code Online (Sandbox Code Playgroud)

和我的 cron 工作

在此输入图像描述

San*_*esh 5

更改您的命令以运行artisan schedule:run. php请注意,路径后面有一个空格,这告诉 cron 作业执行 php 脚本,即 artisan 文件。

php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
Run Code Online (Sandbox Code Playgroud)

将您的调度程序更改为

$schedule->command('check:reserve')->everyMinute();
Run Code Online (Sandbox Code Playgroud)