<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、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                >[info] 定時計劃任務 1. Composer 導入 `workerman` ``` composer require workerman/workerman ``` 2. 控制臺創建 Timer 命令 ``` php think make:command Timer ``` 3. 實現 Timer ~~~ <?php declare (strict_types = 1); namespace app\command; use think\console\Command; use think\console\Input; use think\console\input\Argument; use think\console\input\Option; use think\console\Output; use Workerman\Worker; class Timer extends Command { /** * @var int */ protected $timer; /** * @var int|float */ //如需更改時間 請更改 interval 以秒為單位 protected $interval = 2; protected function configure() { // 指令配置 $this->setName('timer') ->addArgument('status', Argument::REQUIRED, 'start/stop/reload/status/connections') ->addOption('d', null, Option::VALUE_NONE, 'daemon(守護進程)方式啟動') ->addOption('i', null, Option::VALUE_OPTIONAL, '多長時間執行一次') ->setDescription('開啟/關閉/重啟 定時任務'); } protected function init(Input $input, Output $output) { global $argv; if ($input->hasOption('i')) $this->interval = floatval($input->getOption('i')); $argv[1] = $input->getArgument('status') ?: 'start'; if ($input->hasOption('d')) { $argv[2] = '-d'; } else { unset($argv[2]); } } /** * 運行該命令行類的時候要執行的具體業務邏輯代碼 */ protected function execute(Input $input, Output $output) { $this->init($input, $output); //創建定時器任務 $task = new Worker(); $task->count = 1; $task->onWorkerStart = [$this, 'start']; $task->runAll(); // 指令輸出 $output->writeln('timer'); } public function start() { $last = time(); $task = [6 => $last, 10 => $last, 30 => $last, 60 => $last, 180 => $last, 300 => $last]; $this->timer = \Workerman\Lib\Timer::add($this->interval, function () use (&$task) { //每隔2秒執行一次 try { $now = time(); foreach ($task as $sec => $time) { if ($now - $time >= $sec) { // 每隔$sec秒執行一次 $task[$sec] = $now; // 業務邏輯方法調用 } } } catch (\Throwable $e) { } }); } public function stop() { //手動暫停定時器 \Workerman\Lib\Timer::del($this->timer); } } ~~~ 4. 注冊 Timer 命令(修改 `console.php` 文件) ``` 'commands' => [ //定時任務命令 'timer'=>\app\command\Timer::class, ], ``` 5. 啟動/關閉 ``` php think timer php think timer start php think timer stop php think timer restart ``` 6. 參數說明: ``` Usage: timer [options] [--] <status> Arguments: status start/stop/reload/status/connections Options: --d daemon(守護進程)方式啟動 --i[=I] 多長時間執行一次,可以精確到0.001 ```
                  <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>

                              哎呀哎呀视频在线观看