fedemotta/yii2-cronjob
Composer 安装命令:
composer require fedemotta/yii2-cronjob
包简介
Yii2 extension to help in the creation of automated console scripts
README 文档
README
Yii2 extension to help in the creation of automated console scripts. It helps to manage the execution of console scripts, for example avoiding the execution if the previous cron is already running. It generates a history of cron executed, with the time spent and helps to batch processing the script.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist fedemotta/yii2-cronjob "*"
or add
"fedemotta/yii2-cronjob": "*"
to the require section of your composer.json file.
This extension needs a database to manage the cron job execution. Run the following migration to create the table structure:
yii migrate --migrationPath=@fedemotta/cronjob/migrations
Usage
Once the extension is installed, you can use it as a helper in your console controller.
See the following example:
<?php namespace somenamespace\controllers; use fedemotta\cronjob\models\CronJob; use somenamespace\SomeModel; use yii\console\Controller; /** * SomeContrController controller */ class SomeContrController extends Controller { /** * Run SomeModel::some_method for a period of time * @param string $from * @param string $to * @return int exit code */ public function actionInit($from, $to){ $dates = CronJob::getDateRange($from, $to); $command = CronJob::run($this->id, $this->action->id, 0, CronJob::countDateRange($dates)); if ($command === false){ return Controller::EXIT_CODE_ERROR; }else{ foreach ($dates as $date) { //this is the function to execute for each day SomeModel::some_method((string) $date); } $command->finish(); return Controller::EXIT_CODE_NORMAL; } } /** * Run SomeModel::some_method for today only as the default action * @return int exit code */ public function actionIndex(){ return $this->actionInit(date("Y-m-d"), date("Y-m-d")); } /** * Run SomeModel::some_method for yesterday * @return int exit code */ public function actionYesterday(){ return $this->actionInit(date("Y-m-d", strtotime("-1 days")), date("Y-m-d", strtotime("-1 days"))); } }
Run the SomeModel::some_method for today:
./yii some-contr
For yesterday:
./yii some-contr/yesterday
For some custom dates like this:
./yii some-contr/init 2010-10-10 2012-10-10
And you can add a cron job to run every 10 minutes with some controller action like this:
*/10 * * * * /path/to/yii/application/yii some-contr/yesterday >> /var/log/console-app.log 2>&1
fedemotta/yii2-cronjob 适用场景与选型建议
fedemotta/yii2-cronjob 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 34.16k 次下载、GitHub Stars 达 22, 最近一次更新时间为 2015 年 10 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「console」 「cron」 「schedule」 「extension」 「job」 「crontab」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fedemotta/yii2-cronjob 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fedemotta/yii2-cronjob 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fedemotta/yii2-cronjob 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This class provides you with an easy-to-use interface to progress bars.
Symfony bundle to monitor and execute commands
A Laravel package to retrieve data from Google Search Console
Additional artisan commands for Laravel
Enables the creation of cron-jobs tasks to be consumed by symfony/messenger
Scheduling extension for Yii2 framework
统计信息
- 总下载量: 34.16k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 22
- 点击次数: 10
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-07