phantom-d/yii2-file-daemon

文件处理的 Yii2 守护进程

安装: 5

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:yii2-extension

dev-master / 2.0.x-dev 2016-05-03 11:12 UTC

This package is auto-updated.

Last update: 2024-09-09 19:49:24 UTC


README

Yii2 文件处理守护进程

安装

通过 Composer 获取包

推荐通过 composer 安装此扩展。

执行以下命令

php composer.phar require --prefer-dist phantom-d/yii2-file-daemon "dev-master"

或者将以下内容添加到您的 composer.json 文件的 require 部分

"phantom-d/yii2-file-daemon": "dev-master"

应用配置

1 - 为了进行初始配置,建议复制基本配置文件。基本配置文件位于 @vendor/phantom-d/yii2-file-daemon/config/daemons.php 目录中

创建目录

  • Yii2-base 模板 - @app/config/daemons
  • Yii2-advanced 模板 - @app/common/config/daemons

将基本配置文件复制到创建的目录中。基本配置文件中指定了控制其他守护进程启动和停止的守护进程设置。

2 - 创建一个名为 FileServerDaemonController.php 的守护进程控制器文件,该文件将扮演文件处理守护进程的角色

  • Yii2-base 模板 - @app/console
<?php

namespace app\console;

use phantomd\filedaemon\console\controllers\FileDaemonController;

/**
 * Class FileServerDaemonController.
 */
class FileServerDaemonController extends FileDaemonController
{

}
  • Yii2-advanced 模板 - @app/console/controllers
<?php

namespace console\controllers;

use phantomd\filedaemon\console\controllers\FileDaemonController;

/**
 * Class FileServerDaemonController.
 */
class FileServerDaemonController extends FileDaemonController
{

}

3 - 创建一个名为 WatcherDaemonController.php 的观察者控制器文件,该文件将扮演文件处理守护进程的角色

  • Yii2-base 模板 - @app/console
<?php

namespace app\console;

use phantomd\filedaemon\console\controllers;

/**
 * Class WatcherDaemonController.
 */
class WatcherDaemonController extends controllers\WatcherDaemonController
{

}
  • Yii2-advanced 模板 - @app/console/controllers
<?php

namespace console\controllers;

use phantomd\filedaemon\console\controllers;

/**
 * Class WatcherDaemonController.
 */
class WatcherDaemonController extends controllers\WatcherDaemonController
{

}

4 - 创建一个名为 DaemonController.php 的 REST 控制器文件,您将通过它添加数据以安排任务处理

  • Yii2-base 模板 - @app/controllers
<?php

namespace app\controllers;

/**
 * Class DaemonController. Frontend REST controller.
 */
class DaemonController extends \phantomd\filedaemon\frontend\controllers\DaemonController
{

    /**
     * @var string Daemon name in configuration
     */
    protected static $configAlias = 'file-server';

}
  • Yii2-advanced 模板 - @app/frontend/controllers
<?php

namespace frontend\controllers;

/**
 * Class DaemonController. Frontend REST controller.
 */
class DaemonController extends \phantomd\filedaemon\frontend\controllers\DaemonController
{

    /**
     * @var string Daemon name in configuration
     */
    protected static $configAlias = 'file-server';

}

5 - 为了持续运行观察者,将以下行添加到 crontab

5 * * * * /{PATH/TO/YII/PROJECT}/yii watcher-daemon --demonize=1

观察者不能启动两次,只能有一个进程在工作。