PHPackages                             sqonk/phext-detach - 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. sqonk/phext-detach

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

sqonk/phext-detach
==================

Detach is a library for running tasks inside of a PHP script in parallel using forked processes.

1.2.1(3y ago)0901MITPHPPHP ^8

Since Apr 2Pushed 2y ago1 watchersCompare

[ Source](https://github.com/sqonk/phext-detach)[ Packagist](https://packagist.org/packages/sqonk/phext-detach)[ RSS](/packages/sqonk-phext-detach/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (3)Versions (17)Used By (0)

PHEXT Detach
============

[](#phext-detach)

[![Minimum PHP Version](https://camo.githubusercontent.com/a059fb88d3ff5fe22ed8bf35e3309c8ce74b414e8efe9cf66b7cc7a111ae78b9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344253230382d79656c6c6f77)](https://php.net/)[![License](https://camo.githubusercontent.com/e3d584625d5a65f768ca34cf2e2486fe3578f7f9f7f6c1c07548809f8ca8c0f2/68747470733a2f2f73716f6e6b2e636f6d2f6f70656e736f757263652f6c6963656e73652e737667)](license.txt)

Detach is a library for running tasks inside of a PHP script in parallel using forked processes. It clones a seperate process (based on the parent) and executes the requested callback.

It is light weight and relies on little more than the PCNTL and APCu PHP extensions plus a minor set of composer packages.

Detach is also minimalist in nature with just a small set of functions and classes to memorise. There is no event system and no architecture to learn, allowing it to fit easily within an existing code structure.

See the [examples](examples.md) for a quick start guide.

While the spawned tasks have the ability to return data back to the parent there is also the option of using Channels, a loose implementation of channels from the Go language, which provide a simple way of allowing independent processes to send and receive data between one another.

Channels can also be used as logic gates for controlling the execution of various tasks by forcing them to wait for incoming data where required.

Install
-------

[](#install)

Via Composer

```
$ composer require sqonk/phext-detach
```

### Updating past V1.0

[](#updating-past-v10)

Release 1.1 *changes the value returned* from both a `Channel` and a `BufferedChannel` when they are closed. Previously they would return `NULL`, now they return the constant `CHAN_CLOSED`. This was done in order to clearly differentiate between null values intentionally inserted into a channel and channel closure.

Code written previously akin to the following:

```
while ($value = $chan->get()) {
	 // process value.
}
```

Should now be written as follows:

```
while (($value = $chan->get()) !== CHAN_CLOSED) {
	 // process value.
}
```

Alternatively, for the purposes of maintaining simpler syntax, you can now use a generator:

```
// function call..
foreach ($chan->incoming() as $value) {
  // process value.
}

// or directly passing the object as the iterator..
foreach ($chan as $value) {
  // process value.
}
```

### Updating from V0.4

[](#updating-from-v04)

Release 0.5+ adjusts the way Dispatcher::map() works so that it automatically builds and starts the TaskMap, returning the result of `->start()` on the map object. Its parameters have also been expanded to accept the various TaskMap configuration options directly, in preparation for named parameters in PHP8.

### Updating from V0.3

[](#updating-from-v03)

Release 0.4+ is a significant update from previous versions. *It will break existing code that was built to use V0.3.*

Most notably, the class that was formerly named `Channel` has been renamed to `BufferedChannel` and a new `Channel` class has taken its place. You can read more about both classes below.

Also, later in development, the file-based data storage for transferring data between tasks was switched to APCu, now requiring the extension in addition to PCNTL.

Documentation
-------------

[](#documentation)

[API Reference](docs/api/index.md) now available.

Examples
--------

[](#examples)

Skim through the [example code](examples.md) for a quick start guide on the basic concepts.

Credits
-------

[](#credits)

Theo Howell

Please see original concept of pnctl Threading by Tudor Barbu @ [motanelu/php-thread](https://github.com/motanelu/php-thread)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](license.txt) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity64

Established project with proven stability

 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 ~70 days

Recently: every ~167 days

Total

15

Last Release

1237d ago

Major Versions

0.5.0 → 1.0.02021-02-04

PHP version history (4 changes)0.3PHP ^7.3

0.5.0PHP ^7.3 || ^8.0.0

1.0.0PHP ^7.3 || ^7.4 || ^8.0.0

1.2.0PHP ^8

### Community

Maintainers

![](https://www.gravatar.com/avatar/d613b1fb90e5ed5b8207818496ae9c90b7d3b54890803f0af3279c2e7fbd9771?d=identicon)[sqonk](/maintainers/sqonk)

---

Top Contributors

[![sqonk](https://avatars.githubusercontent.com/u/55817417?v=4)](https://github.com/sqonk "sqonk (211 commits)")

---

Tags

concurrencyconcurrentparallelpcntlmultitaskingmulti-tasking

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sqonk-phext-detach/health.svg)

```
[![Health](https://phpackages.com/badges/sqonk-phext-detach/health.svg)](https://phpackages.com/packages/sqonk-phext-detach)
```

###  Alternatives

[arara/process

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

16861.7k2](/packages/arara-process)[veewee/composer-run-parallel

Run composer tasks in parallel

91748.2k13](/packages/veewee-composer-run-parallel)[duncan3dc/fork-helper

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

73548.0k4](/packages/duncan3dc-fork-helper)[mkraemer/react-pcntl

PCNTL bindings for ReactPHP

57289.0k9](/packages/mkraemer-react-pcntl)[recca0120/laravel-parallel

64116.7k](/packages/recca0120-laravel-parallel)[bluepsyduck/symfony-process-manager

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

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

PHPackages © 2026

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