簡體   English   中英

在共享主機和laravel中創建Cron Job

[英]Create Cron Job in shared host and 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');
    }
}

我的內核課

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();
    }
}

和我的工作

在此處輸入圖片說明

更改您的命令以運行artisan schedule:run 請注意, php和路徑后面有一個空格,它告訴cron作業執行php腳本,即artisan文件。

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

將您的調度程序更改為

$schedule->command('check:reserve')->everyMinute();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM