99re热这里只有精品视频,7777色鬼xxxx欧美色妇,国产成人精品一区二三区在线观看,内射爽无广熟女亚洲,精品人妻av一区二区三区

定時調用 Artisan 命令

2018-02-24 15:53 更新

過去,開發(fā)者會對每個他們想要調用的命令行指令建立 Cron 對象。然而,這很令人頭痛。你的命令行指令調用不再包含在版本控制里面,并且你必須 SSH 進入你的服務器以添加 Cron 對象。讓我們來讓生活變得更輕松。Laravel 命令調用器允許你順暢地且語義化地定義命令調用在 Laravel 里面,而且你的服務器只需要一個 Cron 對象。

你的命令調用保存在 app/Console/Kernel.php 文件。你會在這個類里看到一個 schedule 方法。為了幫助您開始,方法里面包含一個簡單的例子。你可以依照你需要的自由地添加任何數量的預定工作到 Schedule 對象。你只需要添加這個 Cron 對象到服務器:

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

這個 Cron 將會每分鐘調用 Laravel 命令調用器。接著,Laravel 評估你的預定工作并在時間到時執(zhí)行工作。這不能再更簡單了!

更多調用的例子

讓我們來多看幾個調用的例子:

調用閉包

$schedule->call(function()
{
    // 執(zhí)行一些任務...

})->hourly();

調用終端機命令

$schedule->exec('composer self-update')->daily();

自己配置 Cron 表達式

$schedule->command('foo')->cron('* * * * *');

頻繁的工作

$schedule->command('foo')->everyFiveMinutes();

$schedule->command('foo')->everyTenMinutes();

$schedule->command('foo')->everyThirtyMinutes();

每天一次的工作

$schedule->command('foo')->daily();

每天一次在特定時間 (24 小時制) 的工作

$schedule->command('foo')->dailyAt('15:00');

每天兩次的工作

$schedule->command('foo')->twiceDaily();

每個工作日執(zhí)行的工作

$schedule->command('foo')->weekdays();

每周一次的工作

$schedule->command('foo')->weekly();

// 調用每周一次在特定的日子 (0-6) 和時間的工作...
$schedule->command('foo')->weeklyOn(1, '8:00');

每月一次的工作

$schedule->command('foo')->monthly();

特定日期的工作

$schedule->command('foo')->mondays();
$schedule->command('foo')->tuesdays();
$schedule->command('foo')->wednesdays();
$schedule->command('foo')->thursdays();
$schedule->command('foo')->fridays();
$schedule->command('foo')->saturdays();
$schedule->command('foo')->sundays();

Prevent Jobs From Overlapping

By default, scheduled jobs will be run even if the previous instance of the job is still running. To prevent this, you may use the withoutOverlapping method:

$schedule->command('foo')->withoutOverlapping();

In this example, the foo command will be run every minute if it is not already running.

限制應該執(zhí)行工作的環(huán)境

$schedule->command('foo')->monthly()->environments('production');

指定工作在當應用程序處于維護模式也應該執(zhí)行

$schedule->command('foo')->monthly()->evenInMaintenanceMode();

只允許工作在閉包返回 true 的時候執(zhí)行

$schedule->command('foo')->monthly()->when(function()
{
    return true;
});

將預定工作的輸出發(fā)送到指定的 E-mail

$schedule->command('foo')->sendOutputTo($filePath)->emailOutputTo('foo@example.com');

注意: 你必須先把輸出存到文件中才可以發(fā)送 email。

將預定工作的輸出發(fā)送到指定的路徑

$schedule->command('foo')->sendOutputTo($filePath);

在預定工作執(zhí)行之后 Ping 一個給定的 URL

$schedule->command('foo')->thenPing($url);
以上內容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號