2017 © Pedro Peláez
 

symfony-bundle daemon-bundle

Symfony2 Daemon Bundle

image

miksoftware/daemon-bundle

Symfony2 Daemon Bundle

  • Monday, June 26, 2017
  • by m1ksoftware
  • Repository
  • 1 Watchers
  • 5 Stars
  • 43,981 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 4 % Grown

The README.md

DaemonBundle

PayPayl donate button Latest Stable Version Latest Unstable Version License, (*1)

DeamonBundle allows to easily convert your Symfony2 console scripts into system daemons. To use DaemonBundle pcntl is required to be configured in your PHP binary., (*2)

DaemonBundle is a based in the PEAR library System_Daemon which was created by Kevin Vanzonneveld and it is highly inspaired by uecode/daemon-bundle., (*3)

System_Daemon Package

System_Daemon is a PHP class that allows developers to create their own daemon applications on Linux systems. The class is focussed entirely on creating and spawning standalone daemons. More information can be found at:, (*4)

Installation

  1. Add this bundle to the composer.json file of your project., (*5)

    php composer.phar require miksoftware/daemon-bundle dev-master
    
  2. Add the bundle to your application kernel., (*6)

    // app/AppKernel.php
    public function registerBundles()
    {
        return array(
            // ...
            new MikSoftware\DaemonBundle\MikSoftwareDaemonBundle()
            // ...
        );
    }
    
  3. Configure the bundle by adding parameters to the config.yml or parameters.yml file:, (*7)

    # app/config/config.yml
    
    mik_software_daemon:
        daemons:
            <command name>: ~
    

Configuration Parameters

To change any configuration setting, you could add required parameters to your project config. Following, an example of a minimal required configuration., (*8)

mik_software_daemon:
    daemons:
        <daemon_id_name>: ~

Other available parameters (with default values):, (*9)

mik_software_daemon:
    daemons:
        <daemon_id_name>: ~
            appName: systemDaemon
            appDir: %kernel.root_dir%
            appDescription: System Daemon
            logDir: %kernel.logs_dir%
            authorName: ~
            authorEmail: ~
            appPidDir: %kernel.cache_dir%/daemons/
            sysMaxExecutionTime: 0
            sysMaxInputTime: 0
            sysMemoryLimit: 1024M
            appUser: www-data
            appGroup: www-data
            appRunAsGID: 1000
            appRunAsUID: 1000
            logVerbosity: info

Usage

  1. Create a Symfony2 command that extends from DaemonizedCommand:, (*10)

    <?php
    
    namespace <Application>\<Bundle>\Command;
    
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;
    use Symfony\Component\Console\Input\InputArgument;
    use MikSoftware\DaemonBundle\Commnad\DaemonizedCommand;
    
    class <Name>Command extends DaemonizedCommand
    {
        protected function configureDaemonCommand()
        {
            $this
                ->setName('<name>')
                ->setDescription('<description>')
                ->setHelp('Usage <info>php app/console <name> start|stop|restart</info>');
        }
    
        /**
         * Starts asynchronous release:deploy commands for queue items.
         */
        protected function daemonLogic()
        {
            // Log something
            $this->getContainer()->get('logger')->info('Daemon is running!');
            // And then sleep for 5 seconds
            $this->daemon->iterate(1);
        }
    }
    
  2. Run your daemon, (*11)

    mik@mbp:~$ php app/console <name> start
    mik@mbp:~$ php app/console <name> stop
    mik@mbp:~$ php app/console <name> restart
    

The methods start, stop and restart will be automatically added to your Symfony2 command. It is possible to add new methods to your command as follow:, (*12)

<?php
    // ...
    class <Name>Command extends DaemonizedCommand
    {
        protected function configureDaemonCommand()
        {
            $this->addMethods(array('status'));        
            $this
                ->setName('<name>')
                ->setDescription('<description>')
                ->setHelp('Usage <info>php app/console <name> start|stop|restart</info>');
        }

        // ...

        protected function status()
        {
            // TODO: implement the new method
        }
    }

License

DaemonBundle is completly open and it is released under the terms of BSD 3-Clause., (*13)

Copyright (c) 2013-2014, Michele Nucci All rights reserved., (*14)

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:, (*15)

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the M1KSoftware and Michele Nucci nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY MICHELE NUCCI ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MICHELE NUCCI BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE., (*16)

The Versions

26/06 2017

dev-master

9999999-dev https://github.com/m1ksoftware/daemon-bundle.git

Symfony2 Daemon Bundle

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.2

 

The Development Requires

php symfony2 daemon

06/05 2014

0.9.3

0.9.3.0 https://github.com/m1ksoftware/daemon-bundle.git

Symfony2 Daemon Bundle

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.2

 

The Development Requires

php symfony2 daemon

05/05 2014

0.9.2

0.9.2.0 https://github.com/m1ksoftware/daemon-bundle.git

Symfony2 Daemon Bundle

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.3.2

 

The Development Requires

php symfony2 daemon