visavi/crontask 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

visavi/crontask

最新稳定版本:v2.0.0

Composer 安装命令:

composer require visavi/crontask

包简介

Simple PHP cron tasks

README 文档

README

Total Downloads Latest Stable Version Latest Unstable Version License

Introduction

This package contains a simple PHP cron task scheduler that helps you version control your cron jobs.

Requirements

This library package requires PHP 7.0 or later

Installation

Installing via Composer

The recommended way to install crontask is through Composer.

Next, run the Composer command to install the latest version of crontask:

composer require visavi/crontask

After installing, you need to require Composer's autoloader:

require 'vendor/autoload.php';

Once you've created your task list script (see Usage below) open a linux shell add the following line to crontab (crontab -e):

* * * * * php /path/cron.php

Usage

The following example shows how to schedule a HelloDaily task (simple echo example) and a ShellMonday task (running a shell task example).

class HelloDailyTask extends \Crontask\Tasks\Task
{
    public function run()
    {
        $this->setOutput('Hello World');
    }
}

class ShellMondayTask extends \Crontask\Tasks\Shell
{
    protected $command = "echo Hello Monday";
}

$taskList = new \Crontask\TaskList();

// Add task to run at 12:00 every day
$taskList->addTask((new HelloDailyTask)->setExpression('12 0 * * *'));

// Add task to run every hour
$taskList->addTask((new HelloDailyTask)->setExpression('@hourly'));

// Add task to run at 12:00 every Monday
$taskList->addTask((new ShellMondayTask)->setExpression('12 0 * * 1'));

// or
$taskList->addTasks([
    (new HelloDailyTask)->setExpression('12 0 * * 1'),
    (new HelloDailyTask)->setExpression('@hourly'),
    (new ShellMondayTask)->setExpression('12 0 * * 1'),
]);

$taskList->run();

CRON Expressions

A CRON expression is a string representing the schedule for a particular command to execute. The parts of a CRON schedule are as follows:

*    *    *    *    *
-    -    -    -    -
|    |    |    |    |
|    |    |    |    |
|    |    |    |    +----- day of week (0 - 7) (Sunday=0 or 7)
|    |    |    +---------- month (1 - 12)
|    |    +--------------- day of month (1 - 31)
|    +-------------------- hour (0 - 23)
+------------------------- min (0 - 59)

Mappings

@yearly   => 0 0 1 1 *
@annually => 0 0 1 1 *
@monthly  => 0 0 1 * *
@weekly   => 0 0 * * 0
@daily    => 0 0 * * *
@hourly   => 0 * * * *

License

The class is open-sourced software licensed under the MIT license

统计信息

  • 总下载量: 16.55k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 1
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-20