battis/autocrontabjob
最新稳定版本:v1.0.1
Composer 安装命令:
composer require battis/autocrontabjob
包简介
An object-oriented approach to scheduling regular cron jobs automatically
README 文档
README
An object-oriented approach to scheduling regular cron jobs automatically
Install
Include in your composer.json:
"require": { "battis/autocrontabjob": "~1.0" }
Use
This object requires a bit of prior preparation before use:
- Extend the abstract
Battis\AutoCrontabJobclass and implement the abstractscheduledJob()method. - Create a script that will be run regularly as a Cron job, that instantiates your class and calls its
scheduledJob()method.
Gotcha warning: Remember that, when a script is run by cron, it is not run by Apache, so it will not generate output to the Apache log files. Handily, there is a log built-in that you can use (see below). By default, the log will be generated in the same directory as the script and be similarly named (.log instead of .php).
A sample script file (which is an all-in-one, also extending the abstract class), called MyJob.php:
<?php require_once('vendor/autoload.php'); // extend the abstract class with our own scheduledJob() method class MyJob extends Battis\AutoCrontabJob { public function scheduledJob() { $this->log->log('I did something!'); } } // instantiate our class $job = new MyJob( 'example', __FILE__, // *this* file will be called by crontab '*/5 * * * *' // run every five minutes (woo hoo!) ); // fire the scheduledJob() method $job->scheduledJob(); ?>
统计信息
- 总下载量: 67
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: LGPL-3.0
- 更新时间: 2015-08-11