繁体   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