corzcode/yii2-swoole-crontab
Composer 安装命令:
composer require corzcode/yii2-swoole-crontab
包简介
yii2 crontab developed based on swoole
README 文档
README
The preferred way to install this extension is through composer:
php composer.phar require corzcode/yii2-swoole-crontab dev-master
Basic Usage
main.php add config
return [ 'bootstrap' => [ 'cron', // 自动任务系统 ], 'components' => [ 'cron' => [ 'class' => 'yii\crontab\Crontab', 'config'=>[ 'user' => 'www', 'group' => 'www', 'pid-file' => '@runtime/cron.pid', 'log-file' => '@runtime/cron/run_cron.log' ], 'cronfile' => __DIR__ . "/cron.php" ], ] ]
add cron.php file
<?php /** * 自动任务配置 以时间整点计算 * 'cron名称'=> array('interval' => 执行时间秒整数, 'offset'=> 时间偏移值秒整数, 'process' => 进程数); * 时间起点为周一 每周二执行可以设'interval' => 86400*7, 'offset'=> 86400*2 * 'cron名称'=> array('crontab' => * '0 1 2 3 4 5'); * * * * * * * * | | | | | | * | | | | | +------ day of week (0 - 6) (Sunday=0) * | | | | +--------- month (1 - 12) * | | | +------------ day of month (1 - 31) * | | +--------------- hour (0 - 23) * | +------------------ min (0 - 59) * +--------------------- sec (0-59) * 不支援week day同时设定 */ return array( 'test' => array('interval' =>5, 'process' =>2), 'test/do' => array('crontab' => "* * * * * *", 'process' =>10, 'log'=>'@runtime/cron/run_test_do.log'), );
Cron controller
namespace console\controllers; use yii\console\Controller; use Yii; class TestController extends Controller { //$num is process num $id is process id public function actionIndex($id = 0, $num = 1) {} public function actionDo($id = 0, $num = 1) {} }
how to run
yii cron/run
service.sh
#!/bin/sh PHPBIN=/path/to/php PHPCLICONF=/path/to/php.ini script_dir=$( cd $(dirname $0); pwd) pidpath="$script_dir/console/runtime" helptxt="Usage: $0 cron {start|stop|reload|restart}" pidfile="$pidpath/$1.pid" cd $script_dir cmd="yii cron/start" case "$2" in start) echo "Starting CLI $1 server " $PHPBIN -c $PHPCLICONF $cmd --pidfile=${pidfile} ;; stop) PID=`cat "${pidfile}"` echo "Stopping CLI $1 server" if [ ! -z "$PID" ]; then kill -15 $PID (( $? == 0 )) && echo -n '' > ${pidfile} [ "$1" == "mq" ] && sleep 5 fi ;; reload) echo "Reload CLI $1 server" PID=`cat "${pidfile}"` if [ ! -z "$PID" ]; then kill -10 $PID fi ;; restart) $0 $1 stop $0 $1 start ;; *) echo $helptxt exit 1 esac exit 0
corzcode/yii2-swoole-crontab 适用场景与选型建议
corzcode/yii2-swoole-crontab 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 50 次下载、GitHub Stars 达 1, 最近一次更新时间为 2021 年 05 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 corzcode/yii2-swoole-crontab 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 corzcode/yii2-swoole-crontab 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 50
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-21