PHPackages                             zjwshisb/process-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. zjwshisb/process-manager

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

zjwshisb/process-manager
========================

A simple php process manager

1.1.1(1y ago)17MITPHPPHP ^8.1

Since Oct 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/zjwshisb/process-manager)[ Packagist](https://packagist.org/packages/zjwshisb/process-manager)[ Docs](https://github.com/zjwshisb/process-manager)[ RSS](/packages/zjwshisb-process-manager/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (5)Versions (7)Used By (0)

A Simple Php Process Manager
============================

[](#a-simple-php-process-manager)

This package provider an easy way to executes php callable in sub-processes with pcntl extension and executes commands in sub-processes with [symfony/process](https://github.com/symfony/process) package.

[![style](https://camo.githubusercontent.com/78ed3810b65a8ebeba418ef3e012a3ffc0f5d2ef717b50851a44c8ad5d4cd2fd/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7a6a7773686973622f70726f636573732d6d616e616765722f7374796c652e796d6c3f6c6f676f3d253344266c6162656c3d7374796c65)](https://github.com/zjwshisb/process-manager/actions)[![test](https://camo.githubusercontent.com/35de8e633becc9a6270cb6534d08240be1fd96ea49d973fbfda656f5cd2a699e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7a6a7773686973622f70726f636573732d6d616e616765722f7465737465722e796d6c3f6c6f676f3d253344266c6162656c3d74657374)](https://github.com/zjwshisb/process-manager/actions)[![phpstan](https://camo.githubusercontent.com/9a0702244f9bbbb7e329fcd20eb4b8a070dd1ea50de35be47f1e43e8ffb3e448/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7a6a7773686973622f70726f636573732d6d616e616765722f7068707374616e2e796d6c3f3f6c6f676f3d253344266c6162656c3d7068707374616e)](https://github.com/zjwshisb/process-manager/actions)[![coverage](https://camo.githubusercontent.com/91de5f727e74ce20718180f04ed5f4c87992cf640a3d1e0d600c949792fb8a7a/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f7a6a7773686973622f70726f636573732d6d616e61676572)](https://github.com/zjwshisb/process-manager/actions)Example
-------

[](#example)

Setting multiple process to consume job or run shell commands.

First, white a script like below.

```
// script.php
$manager = new \Zjwshisb\ProcessManager\Manager();
$manager->setLogger();
// setting php callback
$manager->spawnPhp(function () {
  $count = 1;
  // pseudocode
  // get job to do
  // for Prevent memory leakage, after reach 100 times, exit
  while ($count handle();
        $count++;
    } else {
      sleep(1);
    }
  }
})
// 10 processes to run
->setProcessCount(10);
// processes will always restart after exit.
->setRuntime(0);
// or execute shell commands,
$manager->spawnCmd(["shell command"])
->setProcessCount(10);
->setRuntime(0);
// can call spawnPhp/spawnCmd multiple times to add different jobs.
$manager->start();
```

Then, Run the script.php.

```
/path/to/php scipt.php
```

It is better to use supervisor to keep the script alive.

Supervisor config file like below.

```
[program:process-manager]
command=/path/to/php /path/to/script.php
autostart=true
autorestart=true
stderr_logfile=/path/to/stderr.log
stdout_logfile=/path/to/stdout.log
numprocs=1

```

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

[](#installation)

### Requirements

[](#requirements)

- php &gt;= 8.1
- ext-pcntl
- ext-posix
- Linux/Macos

### Composer

[](#composer)

```
composer require zjwshisb/process-manager:1.0
```

Usage
-----

[](#usage)

Basic usage:

```
$manager = new \Zjwshisb\ProcessManager\Manager();
// or
$manager = new \Zjwshisb\ProcessManager\Manager("PHP Process Manager", "/var/runtime/", 100 * 1000);
// custom logger setting, any instance implement Psr\Log\LoggerInterface support
// if null mean set to Monolog\Logger
$manager->setLogger()
// executes the php callback.
$manager->spawnPhp(function () {return "hello world"})
// executes commands.
$manager->spawnCmd(["echo", "hello world"])
        // below methods only support in spawnCmd
        // ->setEnv()
        // ->setInput()
        // ->setWorkingDirectory()
// start all process
$manager->start();
```

Get success output:

```
// spawnCmd is the same usage.
$manager = new \Zjwshisb\ProcessManager\Manager();
$manager->spawnPhp(function () {return "hello world"})
        ->onSuccess(function (\Zjwshisb\ProcessManager\Process\PcntlProcess $process) {
           // this will be "hello world"
           $output = $process->getOutput();
        })
$manager->start();
```

Get error output:

```
// spawnCmd is the same usage.
$manager = new \Zjwshisb\ProcessManager\Manager();
$manager->spawnPhp(function () {
            throw new RuntimeException("hello world")
        })
        ->onError(function (\Zjwshisb\ProcessManager\Process\PcntlProcess $process) {
           // this will be "hello world"
           $output = $process->getErrorOutput();
        })
$manager->start();
```

Set timeout:

```
$manager = new \Zjwshisb\ProcessManager\Manager();

// set timeout, default 60 seconds.
// set to 0 mean no timeout.
// spawnCmd is the same usage.
$manager->spawnPhp(function () {sleep(10);})
        ->setTimeout(5)
        ->onTimeout(function () {
            //any things to do after timeout
        })
$manager->start();
```

Run multiple times:

```
$manager = new \Zjwshisb\ProcessManager\Manager();
// this will echo 1 10 times totally.
// spawnCmd is the same usage.
$manager->spawnPhp(function () {echo  1 . PHP_EOL;})
        // set run times, default to 1
        ->setRunTimes(10)
$manager->start();
```

Run Always:

```
$manager = new \Zjwshisb\ProcessManager\Manager();
// this will echo 1 always util being stop by other signal.
// spawnCmd is the same usage.
$manager->spawnPhp(function () {echo  1 . PHP_EOL;})
// if value set to zero or negative, the callback will run infinitely.
        ->setRunTimes(0)
$manager->start();
```

Set Multiple process:

```
$manager = new \Zjwshisb\ProcessManager\Manager();
// this will "echo 1" 10 times totally.
// spawnCmd is the same usage.
$manager->spawnPhp(function () {echo  1 . PHP_EOL;})
        // set process count, default to 1.
        ->setProcessCount(10)
$manager->start();
```

Multiple process run multiple times:

```
$manager = new \Zjwshisb\ProcessManager\Manager();
// this will "echo 1" 10*10 times totally.
// spawnCmd is the same usage.
$manager->spawnPhp(function () {echo  1 . PHP_EOL;})
        // set process count, default to 1.
        ->setProcessCount(10)
        ->setRunTimes(10)
$manager->start();
```

License
-------

[](#license)

MIT

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Every ~0 days

Total

6

Last Release

561d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8c62f43bf37b1ff57fff28d353c1890e55d0fdeb6895a72241aec6eed2f15a42?d=identicon)[zjwshisb](/maintainers/zjwshisb)

---

Top Contributors

[![zjwshisb](https://avatars.githubusercontent.com/u/11584349?v=4)](https://github.com/zjwshisb "zjwshisb (25 commits)")

---

Tags

pcntlphpprocess-managerprocesscommandspcntlprocesss manager

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/zjwshisb-process-manager/health.svg)

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

###  Alternatives

[duncan3dc/fork-helper

Simple class to fork processes in PHP and allow multi-threading

73548.0k4](/packages/duncan3dc-fork-helper)[arara/process

Provides a better API to work with processes on Unix-like systems

16861.7k2](/packages/arara-process)[jolicode/castor

A lightweight and modern task runner. Automate everything. In PHP.

53541.0k3](/packages/jolicode-castor)[bluepsyduck/symfony-process-manager

A process manager for Symfony processes, able to run them in parallel.

10784.6k3](/packages/bluepsyduck-symfony-process-manager)[graze/supervisor

:vertical\_traffic\_light: Process supervisor for PHP.

999.3k](/packages/graze-supervisor)

PHPackages © 2026

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