PHPackages                             azielinski/simple-process - 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. azielinski/simple-process

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

azielinski/simple-process
=========================

Simple wrapper for PHP pcntl fork functions

45703PHP

Since May 9Pushed 11y ago1 watchersCompare

[ Source](https://github.com/AZielinski/SimpleProcess)[ Packagist](https://packagist.org/packages/azielinski/simple-process)[ RSS](/packages/azielinski-simple-process/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (1)Used By (0)

SimpleProcess
=============

[](#simpleprocess)

This small library makes it simple to use the `pcntl` extension; Also, I strongly encourage you to take a look at the `PThreads` library () which is more powerful than this tiny wrapper; I wrote it just because using PThreads was not an option in my use-case.

Installation
============

[](#installation)

### Requirements

[](#requirements)

```
PHP >= 5.3
pcntl extension installed

```

### Composer

[](#composer)

Just add the following line to your `"require":` section:

```
"azielinski/simple-process": "dev-master"

```

### You do not use composer?

[](#you-do-not-use-composer)

Then just clone the repo :) You will also have to manually `include` all four files.

Basic usage
===========

[](#basic-usage)

Basic usage looks like this:

```
declare(ticks=1); // This part is critical, be sure to include it
$manager = new SimpleProcess\ProcessManager();
$manager->fork(new SimpleProcess\Process(function() { sleep(5); }, "My super cool process"));

do
{
    foreach($manager->getChildren() as $process)
    {
        $iid = $process->getInternalId();
        if($process->isAlive())
        {
            echo sprintf('Process %s is running', $iid);
        } else if($process->isFinished()) {
            echo sprintf('Process %s is finished', $iid);
        }
        echo "\n";
    }
    sleep(1);
} while($manager->countAliveChildren());
```

And that's it! Child processes will execute only the provided callable, so there is no need to worry about "Am I in the right process in this line?"; Parent process continues execution normally after the `->fork()` was called; `ProcessManager` class also takes care of reaping children processes, so you may focus on your application's logic instead of dark corners of `pcntl_*` functions usage.

parent&lt;-&gt;child communication
==================================

[](#parent-child-communication)

ProcessManager may allocate some shared memory for each child process - then you may access it from the parent process:

```
declare(ticks=1); // This part is critical, be sure to include it
$manager = new SimpleProcess\ProcessManager();
$manager->allocateSHMPerChildren(1000); // allocate 1000 bytes for each forked process
for($i=0;$ifork(new SimpleProcess\Process(function(SimpleProcess\Process $currentProcess) {
        $currentProcess->getShmSegment()->save('status', 'Processing data...');
        sleep(5);
        $currentProcess->getShmSegment()->save('status', 'Connecting to the satellite...');
        sleep(5);
    }, $i));
}
$manager->cleanupOnShutdown(); // Register shutdown function that will release allocated shared memory;
                               // It is important to call this after all fork() calls, as we don't want
                               // to release it when child process exits

do
{
    foreach($manager->getChildren() as $process)
    {
        $iid = $process->getInternalId();
        if($process->isAlive())
        {
            echo sprintf('Process %s is running with status "%s"', $iid, $process->getShmSegment()->fetch('status'));
        } else if($process->isFinished()) {
            echo sprintf('Process %s finished execution', $iid);
        }
        echo "\n";
    }
    sleep(1);
} while($manager->countAliveChildren());

$manager->cleanup(); // You can also call cleanup() manually if you want to
```

Other things
============

[](#other-things)

This library comes also with the `Semaphore` class in case you'd need to use semaphores somewhere in your code; Use it like this:

```
$s = SimpleProcess\Semaphore::create('critical_section');
$s->acquire();
$s->release();
```

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/82f8b6f87f741a78784d7453f52734516053272d36325c5cf23b24df0baffe8d?d=identicon)[AZielinski](/maintainers/AZielinski)

---

Top Contributors

[![white-poto](https://avatars.githubusercontent.com/u/4362540?v=4)](https://github.com/white-poto "white-poto (5 commits)")

### Embed Badge

![Health badge](/badges/azielinski-simple-process/health.svg)

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

###  Alternatives

[dekuan/dedid

An unique id generator for distributed database by DeKuan, Inc.

221.4k4](/packages/dekuan-dedid)

PHPackages © 2026

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