2017 © Pedro Peláez
 

library pcntl-signal-handler

PCNTL signal handler for PHP

image

mougrim/pcntl-signal-handler

PCNTL signal handler for PHP

  • Friday, December 9, 2016
  • by Mougrim
  • Repository
  • 1 Watchers
  • 2 Stars
  • 134 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

php-pcntl-signal-handler

Библиотка позволяет назначать несколько обработчиков одного и тогоже сигнала. Особенно это актуально для сигнала SIGHUP., (*1)

Для версии php меньше чем 5.3

Помимо описанного выше класс Mougrim_Pcntl_SignalHandler эмулирует pcntl_signal_dispatch(), которая досупна только с версии php 5.3.0 Входной файл signalExampleRun.php:, (*2)

<?php
// в начале подключаем SignalHandler, что бы был вызван declare(ticks = 1);
require_once dirname(__FILE__) . "/src/lt5.3/Mougrim/Pcntl/SignalHandler.php";
require_once dirname(__FILE__) . "/SignalExample.php";;
$signalHandler = new Mougrim_Pcntl_SignalHandler();
$signalExample = new SignalExample($signalHandler);
$signalExample->run();

Файл SignalExample.php:, (*3)

<?php
class SignalExample
{
    private $signalHandler;

    public function __construct(Mougrim_Pcntl_SignalHandler $signalHandler)
    {
        $this->signalHandler = $signalHandler;
    }

    public function run()
    {
        // добавляем обработчик сигнала SIGTERM
        $this->signalHandler->addHandler(SIGTERM, array($this, 'terminate'));
        // добавляем обработчик сигнала SIGINT
        $this->signalHandler->addHandler(SIGINT, array($this, 'terminate'));

        while(true)
        {
            $this->signalHandler->dispatch();

            // итерация цикла
            echo "итерация цикла\n";
            usleep(300000);
        }
    }

    public function terminate()
    {
        // послать SIGTERM детям
        // ...
        echo "terminate\n";

        exit(0);
    }
}

Для версии php больше либо равно 5.3

Входной файл signalExampleRun53.php:, (*4)

<?php
// в начале подключаем SignalHandler, что бы был вызван declare(ticks = 1);
require_once dirname(__FILE__) . "/src/gte5.3/Mougrim/Pcntl/SignalHandler.php";
require_once dirname(__FILE__) . "/SignalExample53.php";;
$signalHandler = new \Mougrim\Pcntl\SignalHandler();
$signalExample = new SignalExample53($signalHandler);
$signalExample->run();

Файл SignalExample53.php:, (*5)

<?php
class SignalExample53
{
    private $signalHandler;

    public function __construct(\Mougrim\Pcntl\SignalHandler $signalHandler)
    {
        $this->signalHandler = $signalHandler;
    }

    public function run()
    {
        // добавляем обработчик сигнала SIGTERM
        $this->signalHandler->addHandler(SIGTERM, array($this, 'terminate'));
        // добавляем обработчик сигнала SIGINT
        $this->signalHandler->addHandler(SIGINT, array($this, 'terminate'));

        while(true)
        {
            $this->signalHandler->dispatch();

            // итерация цикла
            echo "итерация цикла\n";
            usleep(300000);
        }
    }

    public function terminate()
    {
        // послать SIGTERM детям
        // ...
        echo "terminate\n";

        exit(0);
    }
}

The Versions

09/12 2016

dev-master

9999999-dev https://github.com/mougrim/php-pcntl-signal-handler

PCNTL signal handler for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Avatar Mougrim

signal pcntl pcntl signal handler pcntl signal signal handler

09/12 2016

v1.0.3

1.0.3.0 https://github.com/mougrim/php-pcntl-signal-handler

PCNTL signal handler for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Avatar Mougrim

signal pcntl pcntl signal handler pcntl signal signal handler

25/11 2013

v1.0.2

1.0.2.0 https://github.com/mougrim/php-pcntl-signal-handler

PCNTL signal handler for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Avatar Mougrim

signal pcntl pcntl signal handler pcntl signal signal handler

25/11 2013

v1.0.1

1.0.1.0 https://github.com/mougrim/php-pcntl-signal-handler

PCNTL signal handler for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Avatar Mougrim

signal pcntl pcntl signal handler pcntl signal signal handler

21/11 2013

v1.0.0

1.0.0.0 https://github.com/mougrim/php-pcntl-signal-handler

PCNTL signal handler for PHP

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Avatar Mougrim

signal pcntl pcntl signal handler pcntl signal signal handler