2016-11-10 204 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