<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ### 創建任務 在命令行執行下面的命令生產自定義任務文件,比如說創建一個定時取消訂單的任務`OrderCancel` ~~~bash php artisan make:command OrderCancel ~~~ 命令執行完后會生成`app/Console/Commands/OrderCancel.php`文件 ### 編寫任務 在上一步生成的文件中編寫代碼,`signature`變量為執行的命令,`handle()`方法中寫具體的實現邏輯 ~~~php <?php namespace App\Console\Commands; use Illuminate\Console\Command; class OrderCancel extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'order:cancel'; /** * The console command description. * * @var string */ protected $description = '30分鐘未付款取消訂單'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed * @throws */ public function handle() { echo 'The order has been cancelled'.PHP_EOL; return true; } } ~~~ ### 啟動調度器 #### 執行單個任務 在命令行直接執行自定義的執行命令即可測試方法,例如 ~~~bash php artisan order:cancel ~~~ 會在命令行輸出`The order has been cancelled` #### 執行全部任務 在`app/Console/Kernel.php`的`schedule`方法中添加需要執行的全部任務 ~~~php $schedule->command('order:cancel')->everyMinute(); ~~~ 然后執行下面的命令即可 ~~~bash php artisan schedule:run ~~~ `everyMinute()`是任務調度的時間控制,更多用法可以參考 [Laravel入坑指南(番外)——任務調度 - 咚..咚 - 博客園 (cnblogs.com)](https://links.jianshu.com/go?to=https%3A%2F%2Fwww.cnblogs.com%2Fddcoder%2Fp%2F13455177.html) 注意事項:`php artisan schedule:run`這個命令下`echo`不會在控制臺打印,可以使用`laravel`自帶的`Log`記錄 #### 自動執行任務 在`linux`系統的`crontab`中添加下面的任務,每秒執行一次 ~~~bash * * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1 ~~~ 如果需要精確到毫秒級的定時任務,可以自己寫shell腳本來執行任務調度 ### 并行執行任務 如果有多個任務調度,一般是順序執行的,也就是要等第一個任務執行完成第二個才會開始執行,如果要讓任務并行執行的話,需要在`schedule`方法中調用`runInBackground()`方法,例如 ~~~php $schedule->command('order:cancel')->everyMinute()->runInBackground(); ~~~ ### 任務重復處理 如果一個任務執行需要5秒時間,但是任務是每秒執行的,就會出現上一次任務還沒執行完,同一個任務又開始了,為了避免這種情況,需要在`schedule`方法中調用`withoutOverlapping()`方法,例如 ~~~php $schedule->command('order:cancel')->withoutOverlapping(); //鎖默認24小時失效 $schedule->command('order:cancel')->withoutOverlapping(10); //鎖10分鐘失效 ~~~ 在任務執行的時候會添加一個鎖,在加鎖狀態下任務是不會執行的,知道任務執行完成。當然還可以使用外部的手段來加鎖,比如`文件鎖flock`,或者`redis的setnx`都可以 ### 輸出重定向 在`schedule`方法中調用`appendOutputTo()`方法可以指定輸出流的文件 ~~~php $schedule->command('order:cancel')->appendOutputTo($filePath); ~~~ ### 任務鉤子 使用 `before` 和 `after` 方法,你可以指定在調度任務完成之前和之后要執行的代碼 ~~~php $schedule->command('order:cancel') ->daily() ->before(function () { // 任務即將開始... }) ->after(function () { // 任務已經完成... }); ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看