Laravel 5 Laravel 5.0:任务调度

Laravel 5 Laravel 5.0:任务调度,laravel-5,cron,scheduled-tasks,cron-task,Laravel 5,Cron,Scheduled Tasks,Cron Task,我正在使用Laravel5.0.*,现在我想在我的应用程序中实现cron作业。 我搜索了很多,但什么也没有得到,所有的示例和视频教程都与5.1和5.3相关,甚至我在laravel.com中搜索了5.0版本下的任务调度,但没有显示任何内容 参考视频链接: 在使用了上面的视频参考之后,我在终端中得到了下面的错误 [2016-11-02 08:47:06]local.ERROR:异常“InvalidArgumentException”,消息为“cron”命名空间中未定义任何命令。”在D:\harend

我正在使用Laravel5.0.*,现在我想在我的应用程序中实现cron作业。 我搜索了很多,但什么也没有得到,所有的示例和视频教程都与5.1和5.3相关,甚至我在laravel.com中搜索了5.0版本下的任务调度,但没有显示任何内容

参考视频链接:

在使用了上面的视频参考之后,我在终端中得到了下面的错误

[2016-11-02 08:47:06]local.ERROR:异常“InvalidArgumentException”,消息为“cron”命名空间中未定义任何命令。”在D:\harendar\htdocs\nkbuild\vendor\symfony\console\symfony\Component\console\Application.php:501中

/app/Console/Kernel.php
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 = [
        'App\Console\Commands\Inspire',
        'App\Console\Commands\LogDemo',
    ];

    /**
     * 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('log:demo')->emailOutputTo('harendar@solutionavenues.com');
    }

}
/app/Console/Commands/LogDemo.php

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 = [
        'App\Console\Commands\Inspire',
        'App\Console\Commands\LogDemo',
    ];

    /**
     * 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('log:demo')->emailOutputTo('harendar@solutionavenues.com');
    }

}
<?php namespace App\Console\Commands;

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class LogDemo extends Command {

    /**
     * The console command name.
     *
     * @var string
     */
    protected $name = 'log:demo';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Log Demo command.';

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

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function fire()
    {
        \log::info('I was here @ ', \Carbon\Carbon::now());
    }

    /**
     * Get the console command arguments.
     *
     * @return array
     */
    protected function getArguments()
    {
        return [
            ['example', InputArgument::REQUIRED, 'An example argument.'],
        ];
    }

    /**
     * Get the console command options.
     *
     * @return array
     */
    protected function getOptions()
    {
        return [
            ['example', null, InputOption::VALUE_OPTIONAL, 'An example option.', null],
        ];
    }

}

首先,您需要运行command:php artisan make:console测试(命令名)

然后在app/Console/Commands/test.php下创建一个test.php命令,如下所示:

名称空间App\Console\Commands

使用照明\控制台\命令

类测试扩展命令 { /** *console命令的名称和签名。 * *@var字符串 */ 受保护的$签名='测试'

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

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

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

}

您好,首先您需要运行command:php artisan make:console测试(命令名)

然后在app/Console/Commands/test.php下创建一个test.php命令,如下所示:

名称空间App\Console\Commands

使用照明\控制台\命令

类测试扩展命令 { /** *console命令的名称和签名。 * *@var字符串 */ 受保护的$签名='测试'

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

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

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

}

点击链接,如果您需要帮助,请告诉我。谢谢@AnandMishra,***php/path/to/artisan schedule:run 1>>/dev/null 2>&1当我们使用手动Cron expression时,这是不需要的。是的,但是如果您在服务器上计划,则需要。好的@AnandMishra我可以在本地,我添加了这个命令,php-q/home/server\u name/public\u html/nkbuild/artisan schedule:run 1>>/dev/null 2>&1但不工作请点击链接,如果需要帮助请告诉我谢谢@AnandMishra,***php/path/to/artisan schedule:run 1>>/dev/null 2>&1当我们使用手动Cron ExpressionYes时,这不是必需的,但如果您在服务器上调度它,则需要。ok@AnandMishra我可以在本地测试它吗,可以吗,或者我应该在live server上尝试我添加了这个命令,php-q/home/server\u name/public\u html/nkbuild/artisan schedule:run 1>>/dev/null 2>&1但不工作将所有逻辑放入haldle函数并使用以下命令运行commad:php artisan测试(commandname)我在/home3/skmaism/public_html/nkbuild/vendor/compiled.php:2440的日志中发现了这个错误。我将所有逻辑放入haldle函数,并使用以下命令运行commad:php artisan test(commandname)我在/home3/skmaism/public_html/nkbuild/vendor/compiled.php:2440中找到了这个错误