PHP code example of fly-cms / webman-crontab

1. Go to this page and download the library: Download fly-cms/webman-crontab library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fly-cms / webman-crontab example snippets

shell

return [
    'enable' => true,
    'listen'            => '0.0.0.0:2345',
    'debug'             => true, //控制台输出日志
    'write_log'         => true,// 是否记录任务日志
    'redis' => [
        'host' => 'redis://127.0.0.1:6379',
        'options' => [
            'auth' => null,       // 密码,字符串类型,可选参数
        ]
    ],
    'task_handle' => [ //任务操作类
        1 => \FlyCms\WebmanCrontab\event\UrlTask::class,
        2 => \FlyCms\WebmanCrontab\event\EvalTask::class,
        3 => \FlyCms\WebmanCrontab\event\ShellTask::class
    ],
    'getAllTask' => function(){
        //获取所有任务
        return \app\model\CrontabModel::select()->toArray();
    },
    'getTask' => function($id){
        //获取某个任务
        return \app\model\CrontabModel::where('id',$id)->find();
    },
    'writeRunLog' => function($insert_data){
        //写入运行日志,注意,这个是日志模型,跟其它方法的模型不一样
        \app\model\CrontabLogModel::insertGetId($insert_data);
    },
    'updateTaskRunState' => function($id, $last_running_time){
        //更新任务最后运行时间,这里要把运行次数加 1
        return  \app\model\CrontabModel::where('id',$id)
            ->update([
                'last_running_time' => $last_running_time,
                'running_times' => \think\facade\Db::raw(' running_times + 1')
            ]);
    }
];

shell
    /**
     * @param $crontab
     * @return array
     */
    public static function parse($crontab){

        return ['log'=> $log, 'code' => $code];
    }