2016-11-10 128 views
1

我有计划运行的工匠命令任务,每当我运行工匠命令是不论时间,我给cron作业执行每一次。cron作业

这里是我使用

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

/** 
* 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() 
{  
     //executing function; 
} 
     $this->info('Remainder SMS send successfully !!'); 
} 
} 

控制台,这是我的控制台/ kernel.php文件

class Kernel extends ConsoleKernel 
{ 

protected $commands = [ 
    \App\Console\Commands\Inspire::class, 
    \App\Console\Commands\FileEntryData::class, 
    \App\Console\Commands\CronJobConsole::class, 
]; 

/** 
* Define the application's command schedule. 
* 
* @param \Illuminate\Console\Scheduling\Schedule $schedule 
* @return void 
*/ 
protected function schedule(Schedule $schedule) 
{ 
    $schedule->command('sms:note')->dailyAt('19:00')->sendOutputTo('cronjob-result.php'); 
} 
} 

当我运行PHP的工匠短信:注意是执行每一次。我希望它在特定的时间执行,我有gven。

请帮我一把。

回答

3

这个问题,因为你指定它,仅仅是工匠的正常行为。

您已调度命令,所以它会通过Laravels内部调度驱动指定的时间内执行(阅读下面的cronjob)。但是,您也可以通过在CLI中输入命令来手动执行该命令。

注意:执行命令手动与工匠的调度程序无关。调度程序只在您认为合适时才执行此命令。

所以,你正在寻找的命令是:

php artisan schedule:run 

这通过对指定的时间内注册的命令命令循环,所以到时准备好它只会运行命令。

为了确保Laravel执行你的命令时,它的时间,创建一个cronjob(您的服务器上)运行php artisan schedule:run命令每分钟,Laravel负责剩下的照顾。

从文档(插入的crontab):

* * * * * php /path/to/artisan schedule:run >> /dev/null 2>&1 

古德勒克!

+0

对服务器调度cron作业(或任务)有用的链接:https://technet.microsoft.com/en-us/library/cc748993(v=ws.11).aspx和http://www.cyberciti .BIZ/FAQ /怎么办,我加的作业对时钟守护下的Linux或UNIX的,操作系统/ – Tschallacka