2017 © Pedro Peláez
 

library crontab

manage system crontab and php crontab

image

deluxcms/crontab

manage system crontab and php crontab

  • Friday, July 7, 2017
  • by smister
  • Repository
  • 2 Watchers
  • 2 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 20 % Grown

The README.md

deluxcms-crontab

该插件主要用户yii2管理crontab定期执行任务,用数据库的方式管理crontab,并且可将php的执行的进程,接管到一个php中,而不需要启动多个php执行进程, (*1)

安装

1、下载deluxcms-contrab组件

compser require deluxcms/deluxcms-crontab

2、配置config/main-local.php文件,添加crontab模块

'modules' => [
        'crontab' => [//管理模块
            'class' => 'deluxcms\crontab\Module',
        ],
],

3、导入数据库

php /path/yii migrate --migrationPath=@vendor/deluxcms/crontab/migrations

4、开启exec等权限

编辑php.ini,禁用掉disable_functions获将disable_functions内的exec,shell_exec去掉, (*2)

;disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server

5、如果开启服务(www)没有操作crontab的权限,赋予权限

visudo进行添加一下内容,如果需要限制更多的权限,请参考sudo的使用, (*3)

www     ALL=(ALL:ALL) NOPASSWD:ALL

6、配置crontab

配置config/main-local.php文件,添加crontabManager, (*4)

...
'components' => [
        ...
        'crontabManager' => [
            'class' => 'deluxcms\crontab\components\CrontabManager', //设置manager类
            //'binCrontab' => 'sudo crontab',//设置系统的crontab执行路径
            'crontainerClass' => [ //设置crontab获取的类
                ['class' => 'deluxcms\crontab\components\CrontabDb'],
                [ //这个是执行类我们可以动态添加命令进去
                    'class' =>'deluxcms\crontab\components\CrontabList',
                    'crontabs' =>[
                        '*/2 * * * * ls /tmp',  //格式1
                        [   //格式2
                            'type' => 1, //1系统类型,2php类型
                            'min' => '*',
                            'hour' => '*',
                            'day' => '*',
                            'month' => '*',
                            'week' => '*',
                            'command' => 'ls'
                        ]
                    ]
                ]
            ],
            'phpDeamonConfig' => [ //设置phpdeamon
                //'class' => ''
                'command' => 'php /home/wwwroot/deluxcms/yii phpdeamon &' //执行phpdeamon的脚本
            ],
        ]
        ...
 ],
...
]

8、在console命令执行模式,添加PhpdeamonController.php 如果这里的相对改变了,请改变上面配置文件phpDeamonConfig的文件, (*5)

<?php
namespace console\controllers;

use yii\console\Controller;

class PhpdeamonController extends Controller
{
    public function actions()
    {
        return [
            'index' => [
                'class' => 'deluxcms\crontab\actions\PhpDeamonAction'
            ]
        ];
    }
}

The Versions

07/07 2017

dev-master

9999999-dev

manage system crontab and php crontab

  Sources   Download

MIT

by Avatar smister

yii2 crontab deluxcms crontab manage

02/05 2017

v1.0

1.0.0.0

manage system crontab and php crontab

  Sources   Download

MIT

by Avatar smister

yii2 crontab deluxcms crontab manage