PHPackages                             izabolotnev/fork-manager - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. izabolotnev/fork-manager

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

izabolotnev/fork-manager
========================

Simple fork manager

v1.0(10y ago)019GNU General Public License 2.0 or laterPHPPHP &gt;=5.4

Since Oct 14Pushed 8y ago1 watchersCompare

[ Source](https://github.com/izabolotnev/fork-manager)[ Packagist](https://packagist.org/packages/izabolotnev/fork-manager)[ RSS](/packages/izabolotnev-fork-manager/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

fork-manager
============

[](#fork-manager)

Simple fork manager. It can run tasks once or run it again and again. Good for processing a queues and other schedule purposes.

Requirements
------------

[](#requirements)

- PHP 5.4 or later
- PCNTL extension

Installation
------------

[](#installation)

The recommended installation method for this library is by adding the dependency to your [composer.json](https://getcomposer.org/).

```
{
	"require": {
		"izabolotnev/fork-manager": "~1.0"
	}
}
```

Release notes
-------------

[](#release-notes)

- 1.0.0 (2015-10-14, initial release)

- Added the `ForkManager` class
- Added the `Task` class

Usage
-----

[](#usage)

```
class SampleTask extends \izabolotnev\Task
{

    protected $expectedIterations;

    protected $remainderIterations;

    protected $verbose = false;

    /**
     * @var bool Switch to true if intercepted SIGTERM
     */
    protected $isStopping = false;

    /**
     * @param int  $iterations
     * @param bool $verbose
     */
    public function __construct($iterations, $verbose = false)
    {
        $this->expectedIterations  = max($iterations, 0);
        $this->remainderIterations = $this->expectedIterations;
        $this->verbose             = (bool)$verbose;
    }

    protected function afterFork()
    {
        pcntl_signal(SIGTERM, [$this, 'handlerSigTerm']);

        // For test purposes call handlerSigTerm after Ctrl+C
        pcntl_signal(SIGINT, [$this, 'handlerSigTerm']);
    }

    /**
     * Handler for the SIGTERM signal.
     * Gracefull exit
     */
    public function handlerSigTerm()
    {
        $this->remainderIterations = min($this->expectedIterations, 5);
        $this->isStopping          = true;

        $this->verbose && fputs(\STDOUT, 'Gracefull stop' . PHP_EOL);
    }

    /**
     * Handler for the SIGINT signal/
     * Exit immediately
     */
    public function handlerSigInt()
    {
        $this->expectedIterations = 0;
        $this->isStopping         = true;

        $this->beforeExit();

        exit(0);
    }

    /**
     * @return int
     */
    public function process()
    {
        $date = new \DateTime();

        $pid = getmypid();
        $this->verbose && fputs(\STDOUT, sprintf('Process #%s' . PHP_EOL, $pid));

        $i = 1;

        while ($this->remainderIterations-- > 0) {
            $this->verbose && fputs(\STDOUT, sprintf(
                "Process #%d | %'.03d/%d \033[%sm%s\033[0m" . PHP_EOL,
                $pid,
                $i++,
                $this->expectedIterations,
                $this->isStopping ? '0;33' : '0;32',
                $date->modify('+1 second')->format('Y-m-d H:i:s')
            ));

            sleep(1);
        }

        return 0;
    }
}

$task        = new SampleTask(100, true);
$forkManager = new \izabolotnev\ForkManager($task, 2, [\izabolotnev\ForkManager::DEBUG => true]);

$forkManager->once();
```

License
-------

[](#license)

[GNU General Public License 2.0 or later](https://www.gnu.org/copyleft/gpl.html).

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity58

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3916d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4f1282b778cbd013eac5bac6927030e7df4bc67dc842664897618c48d6b66c9b?d=identicon)[izabolotnev](/maintainers/izabolotnev)

### Embed Badge

![Health badge](/badges/izabolotnev-fork-manager/health.svg)

```
[![Health](https://phpackages.com/badges/izabolotnev-fork-manager/health.svg)](https://phpackages.com/packages/izabolotnev-fork-manager)
```

###  Alternatives

[ergebnis/agent-detector

Provides a detector for detecting the presence of an agent.

144.2M5](/packages/ergebnis-agent-detector)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
