Skip to content

New versions of the zend framework 2 console helper family available now

I happy to announce the release of 1.1.0 of bazzlines zend framework 2 console helper (debian backport) module for php as well as the release of 1.1.0 of bazzlines zend framework 2 console helpermodule for php.
Important changes are:

  • added AbstractConsoleControllerFactory
Translate to de es fr it pt ja

version 1.0.2 of zend framework 2 console helper (debian 6 backport) released

I happy to announce the release of 1.0.2 of bazzlines zend framework 2 console helper (debian backport) module for php. Important changes are:

  • removed dependency to apigen
  • updated dependencies
Translate to de es fr it pt ja

version 1.0.3 of zend framework 2 console helper released

I happy to announce the release of 1.0.3 of bazzlines zend framework 2 console helper module for php. Important changes are:

  • removed apigen dependency
  • added use statement into example
  • added link to demo environment
  • added link to debian 6 / zend framework 2.2 backport
  • added minimum version of zend framework 2 to 2.3.* since AbstractConsoleController is mandatory
  • updated dependencies
Translate to de es fr it pt ja

version 1.0.0 of zend framework 2 console helper (debian 6 backport) released

I am happy to announce the release of 1.0.0 of bazzlines zend framework 2 console helper module for php.
It is a backport of the existing locator generator module.

Translate to de es fr it pt ja

version 1.0.1 of zend framework 2 console helper released

I happy to announce the release of 1.0.1 of bazzlines zend framework 2 console helper module for php. Important changes are:

  • added example code output
  • added apigen
  • moved to usage of "Zend\Mvc\Controller\AbstractConsoleController"
Translate to de es fr it pt ja

version 1.0.0 of zend framework 2 console helper released

I happy to announce the release of 1.0.0 of bazzlines zend framework 2 console helper module for php.
This module should easy up implementing console commands supporting POSIX Signal Handling.
Furthermore, there are some simple but useful methods implemented:

  • getConsole()
  • getParameter($name)
  • getRequest()
  • hasBooleanParameter($shortName = '', $longName = '')
  • hasParameter($name)
  • throwExceptionIfNotCalledInsideAnCliEnvironment()

How can I use it?


namespace MyModule\Controller\Console;

use Exception;

class IndexController extends AbstractConsoleController { public function indexAction() { try { $this->throwExceptionIfNotCalledInsideAnCliEnvironment();

        $this->attachSignalHandler($this);

        //some example items
        //  simple think about a lot of items that indicates longer
        //  processing runtime
        $items = array('one', 'two', 'three', 'four');

        //use implemented method to react on signal handling
        $this->processItems(
            $items,             //big list of items
            $this,              //current object
            'processItem',      //method that should be called for each item
            $arguments = array( //additional arguments for method 'processItem' (if needed)
                'foo',
                'bar'
            )
        );
    } catch (Exception $exception) {
        $this->handleException($exception);
    }
}

/**
 * must be protected since it will be called from the parent
 *
 * @param string $item
 * @param string $stringOne
 * @param string $stringTwo
 */
protected function processItem($item, $stringOne, $stringTwo)
{
    $console = $this->getConsole();
    $console->writeLine(
        'this is item "' . $item .
        '" with string one "' . $stringOne . '"' .
        '" and string two "' . $stringTwo . '"'
    );
}

/**
 * @return boolean
 */
private function beVerbose()
{
    return $this->hasBooleanParameter('v', 'verbose');
}

}

How can I install it?

with packagist


composer require netbazzline/zfconsolehelper:dev-master

manuel


mkdir -p vendor/netbazzline/zfconsolehelper
cd vendor/netbazzline/zfconsolehelper
git clone https://github.com/zfconsole_helper
Translate to de es fr it pt ja

Process Fork Manager for PHP

I'm happy to announce the release of version 1.0.0 from the componen Process Fork Manager for PHP.

What is it good for?

  • Provides OOP style for creating and observing parallel tasks
  • Comes with a TaskInterface to easy up implementing own tasks
  • Comes with thread, memory and time limit management
  • Can be extended by using the build in event dispatcher
  • Is shipped with a lot of examples
  • Supports POSIX signal handling

How can i use it?


$factory = \Net\Bazzline\Component\ProcessForkManager\ForkManagerFactory();
$manager = $factory->create();

/** @var \Net\Bazzline\Component\ProcessForkManager\TaskInterface $task */ $task = new \My\Task();

$manager->addTask($task); $manager->execute();

How can i install it?

Manuel


mkdir -p vendor/netbazzline/phpcomponentprocessforkmanager
cd vendor/netbazzline/phpcomponentprocessforkmanager
git clone https://github.com/bazzline/phpcomponentprocessforkmanager

With packagist


"netbazzline/phpcomponentprocessfork_manager": "1.0.0"
Translate to de es fr it pt ja

POSIX signal handling in a php zend framework 2 console controller action call

I played around with php console applications for a while now. The projects are getting bigger and sometimes, the load on the system or the runtime itself increases a lot.
At night, it made "click" and I asked myself "Are you nuts or why aren't you simple using POSIX signals for your php console applications (like normal people are doing it)?". Thanks to the book Signaling PHP, I could "kickstart" into the topic and created a simple example script.

While solving this problem and migrating some own scripts, I wanted to implement the signal handling in a bigger zend framework 2 project.
Quickly done, I copy/pasted/adapted my example code and thought "this is it". To bad, I need to take one pitfall. I could not debug it right know, but zf2 needs to have the "signal handler method" public. The following code is the final outcome of this adaptation session.


class MyController extends AbstractCliActionController
{
    //AbstractCliActionController extends zend AbstractActionController
    //...usefull controller code
    /**
     * @param AbstractCliActionController $object
     * @param string $method
     */
    protected function attachSignalHandler(AbstractCliActionController $object, $method = 'defaultSignalHandler')
    {
        declare(ticks = 10);

    pcntl_signal(SIGHUP,    array($object, $method));
    pcntl_signal(SIGINT,    array($object, $method));
    pcntl_signal(SIGUSR1,   array($object, $method));
    pcntl_signal(SIGUSR2,   array($object, $method));
    pcntl_signal(SIGQUIT,   array($object, $method));
    pcntl_signal(SIGILL,    array($object, $method));
    pcntl_signal(SIGABRT,   array($object, $method));
    pcntl_signal(SIGFPE,    array($object, $method));
    pcntl_signal(SIGSEGV,   array($object, $method));
    pcntl_signal(SIGPIPE,   array($object, $method));
    pcntl_signal(SIGALRM,   array($object, $method));
    pcntl_signal(SIGCONT,   array($object, $method));
    pcntl_signal(SIGTSTP,   array($object, $method));
    pcntl_signal(SIGTTIN,   array($object, $method));
    pcntl_signal(SIGTTOU,   array($object, $method));
}

/**
 * @param $signal
 */
public function defaultSignalHandler($signal)
{
    echo 'caught signal "' . $signal . '"' . PHP_EOL;
}

}


You can easily extend the method "defaultSignalHandler" to whatever you need (push something to a log, flip a flag to stop execution etc) and thats it. Injoy your work :-).

Thanks to the nice irc freenode channel #zftalk, I can provide a second implementation to prove my example to be right.

Translate to de es fr it pt ja