最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用ThinkPHP框架(thinkphp8.0)創(chuàng)建定時任的操作步驟

 更新時間:2024年01月17日 10:08:13   作者:勇哥哥的技術博客  
這篇文章給大家介紹了使用ThinkPHP框架(thinkphp8.0)創(chuàng)建定時任的操作步驟,文中通過代碼示例給大家介紹的非常詳細,對大家的學習或工作有一定的幫助,需要的朋友可以參考下

1、安裝定時任務composer包

composer require easy-task/easy-task

2、創(chuàng)建命令行處理類文件

php think make:command Task  task

會生成文件:app\command\Task.php

將Task.php文件內容修改如下:

<?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;
 
class Task extends Command
{
    protected function configure()
    {
        //設置名稱為task
        $this->setName('task')
            //增加一個命令參數
            ->addArgument('action', Argument::OPTIONAL, "action", '')
            ->addArgument('force', Argument::OPTIONAL, "force", '');
    }
 
    protected function execute(Input $input, Output $output)
    {
        //獲取輸入參數
        $action = trim($input->getArgument('action'));
        $force = trim($input->getArgument('force'));
 
        // 配置任務,每隔20秒訪問2次網站
        $task = new \EasyTask\Task();
        $task->setRunTimePath('./runtime/');
        $task->addFunc(function () {
            $url = 'https://www.wushengyong.com/';
            file_get_contents($url);
        }, 'request', 20, 2);;
 
        // 根據命令執(zhí)行
        if ($action == 'start')
        {
            $task->start();
        }
        elseif ($action == 'status')
        {
            $task->status();
        }
        elseif ($action == 'stop')
        {
            $force = ($force == 'force'); //是否強制停止
            $task->stop($force);
        }
        else
        {
            exit('Command is not exist');
        }
    }
}

3、配置config\console.php文件

<?php
// +----------------------------------------------------------------------
// | 控制臺配置
// +----------------------------------------------------------------------
return [
    // 指令定義
    'commands' => [
        'task' => 'app\command\Task',
    ],
];

4、執(zhí)行命令(windows請使用cmd):

php think task start  啟動命令
php think task status 查詢命令
php think task stop   關閉命令
php  think  task  stop  force   強制關閉命令

以上就是使用ThinkPHP框架(thinkphp8.0)創(chuàng)建定時任的操作步驟的詳細內容,更多關于ThinkPHP框架創(chuàng)建定時任務的資料請關注腳本之家其它相關文章!

相關文章

最新評論

临泉县| 马鞍山市| 阿勒泰市| 本溪| 靖安县| 静宁县| 山阴县| 沂水县| 徐闻县| 贵溪市| 张家界市| 贺州市| 阆中市| 米林县| 邵阳市| 象山县| 建平县| 旬阳县| 搜索| 江华| 肇庆市| 越西县| 达拉特旗| 根河市| 仁化县| 花莲县| 图片| 灯塔市| 湄潭县| 古交市| 绥中县| 星座| 洪湖市| 兰坪| 皋兰县| 西城区| 枞阳县| 陆川县| 班戈县| 五莲县| 红河县|