huangweijie/think-cron

V2.0.1 2020-11-05 01:52 UTC

This package is auto-updated.

Last update: 2024-04-05 09:24:56 UTC


README

介绍

一个基于thinkphp的通用crontab

安装教程

composer require huangweijie/think-cron

使用说明

请参考CronExpression表达式

配置

项目根目录/config/crontab.php
<?php

return [
    'tasks' => [
        [
            'time' => '0 10,50 */3 * * *',
            'mode' => [
                'command' => ['test', 'think-queue-manage:handle'],
                'callback' => [
                    ["app\admin\controller\JobTest:test1"],
                    [['app\admin\controller\JobTest','test1']], 
                    ["app\admin\controller\JobTest:test1", 'huangweijie,huangweijie2'],
                    ["app\admin\controller\JobTest:test1", ['huangweijie,huangweijie2']], 
                    [['app\admin\controller\JobTest','test1'], ['huangweijie,huangweijie2']] 
                ]
            ]
        ],
        [
            'time' => '* * * * * *',
            'mode' => [
                'command' => ['think-queue-manage:handle']
            ]
        ],
        [
            'time' => '0 2,9,36 */2 * * *',
            'mode' => [
                'callback' => [
                    ["app\admin\controller\JobTest:test1", 'huangweijie']
                ]
            ]
        ],
    ]
];

在系统的计划任务里添加

* * * * * php /path/to/think crontab:handle >> /dev/null 2>&1

注意:linux系统的crontab 不支持秒级定时,CronExpression表达式的秒部分填0