medicorenl/daemon-bundle

该包的最新版本(dev-master)没有可用的许可证信息。

Symfony2守护进程包。

该包的规范仓库似乎已丢失,因此该包已被冻结。

安装数: 1,400

依赖者: 0

建议者: 0

安全: 0

星标: 1

关注者: 6

分支: 0

开放问题: 0

类型:symfony-bundle

dev-master 2013-12-19 10:00 UTC

This package is not auto-updated.

Last update: 2024-06-18 01:46:56 UTC


README

DaemonBundle

一个集成 uecode/daemon 库的 Symfony2 包。

灵感来源于 uecode/daemon-bundle

安装

  1. 安装 Composer

    # Install Composer
    curl -sS https://getcomposer.org/installer | php
  2. 将此包添加到您项目的 composer.json 文件中。

    php composer.phar require medicorenl/daemon-bundle dev-master
  3. 安装后,您需要在项目的引导文件中引入 Composer 的自动加载器。

    // app/autoload.php
    $loader = require __DIR__ . '/../vendor/autoload.php';
  4. 将包添加到您的应用程序内核中。

    // app/AppKernel.php
    public function registerBundles()
    {
        return array(
            // ...
            new DaemonBundle\DaemonBundle(),
            // ...
        );
    }
  5. 通过向 config.yml 文件添加参数来配置包

    # app/config/config.yml
    daemon:
        daemons:
            <command name>:
                appName: <name>
                appDir: %kernel.root_dir%
                appDescription: <description>
                logDir: %kernel.logs_dir%
                appPidDir: %kernel.cache_dir%/daemons/
                sysMaxExecutionTime: 0
                sysMaxInputTime: 0
                sysMemoryLimit: 1024M
                appRunAsGID: 1
                appRunAsUID: 1

使用

  1. 创建一个继承自 ExtendCommand 的命令

    <?php
    
    namespace <Application>\<Bundle>\Command;
    
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    use Symfony\Component\Console\Input\InputArgument;
    use DaemonBundle\Command\ExtendCommand;
    
    class <Name>Command extends ExtendCommand
    {
        /**
         * @var string
         */
        protected $name = '<name>';
    
        /**
         * @var string
         */
        protected $description = '<description>';
    
        /**
         * @var string
         */
        protected $help = 'Usage: <info>php app/console <name> start|stop|restart</info>';
        
        /**
         * Configures command arguments.
         */
        protected function setArguments()
        {
        }
    
        /**
         * Configures command options.
         */
        protected function setOptions()
        {
        }
        
        /**
         * Starts asynchronous release:deploy commands for queue items.
         */
        protected function daemonLogic()
        {
            $this->container->get('logger')->info('Daemon is running!');
            $this->daemon->iterate(5);
        }
    }
  2. 可选地从您的命令创建一个服务

    <service id="<bundle alias>.command.<command alias>" class="<Application>\<Bundle>Bundle\Command\<Name>Command" />