yii2mod/yii2-cron-log
Composer 安装命令:
composer require yii2mod/yii2-cron-log
包简介
Component for logging cron jobs
README 文档
README
Yii2 Cron Log Extension
Component for logging cron jobs.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist yii2mod/yii2-cron-log "*"
or add
"yii2mod/yii2-cron-log": "*"
to the require section of your composer.json.
Configuration
Database Migrations
Before using this extension, we'll also need to prepare the database.
php yii migrate/up --migrationPath=@yii2mod/cron/migrations
Error Handler and File Mutex Setup
Error handler must be defined inside console config, it will be used to log exceptions into database.
FileMutex implements mutex "lock" mechanism via local file system files.
Add the following code to your console application configuration:
'components' => [ 'errorHandler' => [ 'class' => 'yii2mod\cron\components\ErrorHandler', ], 'mutex' => [ 'class' => 'yii\mutex\FileMutex' ], ],
Usage
- To access the list of executed commands, you need to define
CronLogActionin any controller (for example /modules/admin/SettingsController.php):
public function actions() { return [ 'cron' => 'yii2mod\cron\actions\CronLogAction', // Also you can override some action properties in following way: 'cron' => [ 'class' => 'yii2mod\cron\actions\CronLogAction', 'searchClass' => [ 'class' => 'yii2mod\cron\models\search\CronScheduleSearch', 'pageSize' => 10 ], 'view' => 'custom name of the view, which should be rendered.' ] ]; }
This action is used to view list of executed commands: http://project.com/admin/settings/cron
- To log cron actions you should add behavior to all commands that should be logged. In the following example
CronLoggerBehaviorwill be log theindexaction.
namespace app\commands; use yii\console\Controller; /** * This command echoes the first argument that you have entered. * * This command is provided as an example for you to learn how to create console commands. * */ class HelloController extends Controller { public function behaviors() { return [ 'cronLogger' => [ 'class' => 'yii2mod\cron\behaviors\CronLoggerBehavior', 'actions' => ['index'] ], // Example of usage the `MutexConsoleCommandBehavior` 'mutexBehavior' => [ 'class' => 'yii2mod\cron\behaviors\MutexConsoleCommandBehavior', 'mutexActions' => ['index'], 'timeout' => 3600, //default 0 ] ]; } /** * This command echoes what you have entered as the message. * @param string $message the message to be echoed. */ public function actionIndex($message = 'hello world') { echo $message . "\n"; } }
Internationalization
All text and messages introduced in this extension are translatable under category 'yii2mod-cron-log'. You may use translations provided within this extension, using following application configuration:
return [ 'components' => [ 'i18n' => [ 'translations' => [ 'yii2mod-cron-log' => [ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@yii2mod/cron/messages', ], // ... ], ], // ... ], // ... ];
Support us
Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff.
yii2mod/yii2-cron-log 适用场景与选型建议
yii2mod/yii2-cron-log 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 28.58k 次下载、GitHub Stars 达 22, 最近一次更新时间为 2014 年 11 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「yii2 cron log」 「cron log」 「logging cron jobs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 yii2mod/yii2-cron-log 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 yii2mod/yii2-cron-log 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 yii2mod/yii2-cron-log 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony bundle to monitor and execute commands
A custom URL rule class for Yii 2 which allows to create translated URL rules
Scheduling extension for Yii2 framework
Monitoring for scheduled jobs
Stackdriver handler for Monolog (codeinternetapplications/monolog-stackdriver Fork).
Laravel 5.x.x library for integration Monolog Sentry
统计信息
- 总下载量: 28.58k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 23
- 点击次数: 16
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2014-11-26