PHPackages                             jaxwilko/weird-php - 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. jaxwilko/weird-php

ActiveLibrary

jaxwilko/weird-php
==================

Async Php via child processes

v0.0.6(1y ago)3391MITPHP

Since Nov 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/jaxwilko/weird-php)[ Packagist](https://packagist.org/packages/jaxwilko/weird-php)[ RSS](/packages/jaxwilko-weird-php/feed)WikiDiscussions main Synced 1mo ago

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

WeirdPhp
========

[](#weirdphp)

This project aims to add async support to php via dispatching tasks across multiple processes.

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

[](#requirements)

Weird requires:

- PHP &gt;= 8.2
- Access to `pcntl` methods (`proc_open`, `proc_get_status`, `proc_terminate`)

Install
-------

[](#install)

```
composer require jaxwilko/weird-php
```

Usage
-----

[](#usage)

By default, Weird works with the `Promise` class, you can also pass callable arguments however you will not receive output from them.

```
use Weird\Promise;

Promise::make(function (Thread $thread) {
    // do some really cool stuff
    $result = 'Hello world';
    return $result;
})
    ->then(function (string $result) {
        echo $result;
        // Prints: Hello World
    })
    ->catch(function (\Throwable $e) {
        // This will catch any exceptions happening parent process, not the child process.
    })
```

Using the `ProcessManager` we can dispatch multiple processes across as many processes as we want.

```
use Weird\ProcessManager;
use Weird\Processes\Thread;
use Weird\Promise;

$manager = ProcessManager::create()
    ->spawn(Thread::class, processes: 1);

$manager->dispatch([
    // Promise 1
    Promise::make(function () {
        return 'hello';
    })->then(fn ($str) => $str . ' world')
        ->then(fn ($str) => echo $str . PHP_EOL),

    // Promise 2
    Promise::make(function () {
        return 'world';
    })->then(fn ($str) => $str . ' hello')
        ->then(fn ($str) => echo $str . PHP_EOL)
]);
```

> When a new process is created, it loses access to the current global scope, meaning that things such as your autoloader will not be loaded, by default Weird will attempt to load your composer autoload file if found. Alternatively you can provide a file to register your autoloader via the `withBootstrap()` method.

```
$manager = ProcessManager::create()
    ->withBootstrap(__DIR__ . '/vendor/autoload.php')
    ->spawn(Thread::class);
```

Because these processes are being ran async, if you want them to be handled you need to tell the process manager when to check up on them. To wait until all active processes have completed, call `wait()`. Wait also takes a timeout argument which is in seconds as a float.

```
$manager = ProcessManager::create()
    ->spawn(Thread::class, processes: 1);

$manager->dispatch(function () {
    // do something
});

$manager->wait(timeout: 0.5);
```

Alternatively, you can manually call the `tick()` function, which will check for promises being returned by child processes and process them.

```
$manager = ProcessManager::create()
    ->spawn(Thread::class, processes: 1);

$manager->dispatch(
    Promise::make(function () {
        // do something
    })->then(function (string $output) {
        // do something else
    })
);

while ($doingSomethingElse) {
    // ...
    $manager->tick();
    // ...
}
```

### Hints

[](#hints)

`Hint` is a special message that can be sent from a process to give you feedback about what is going on.

To send a `Hint`, you can call the method `\Weird\Messages\Events\Hint::send($message)`.

A `Hint` handler can be registered by calling `registerHintHandler()` on the `ProcessManager` object.

```
$manager->registerHintHandler(function (mixed $message, Process $process) {
    echo $message;
});
```

### UnknownMessage

[](#unknownmessage)

Due to how Weird listens to output streams, any data sent via outputting directly to the buffer will be captured as an `UnknownMessage`. These can be listened for via calling `registerUnknownMessageHandler()` on the `ProcessManager`object.

```
$manager->registerUnknownMessageHandler(function (mixed $message, Process $process) {
    echo $message;
});
```

Processes
---------

[](#processes)

Included in Weird is the `Thread` process, this allows you to execute multiple async php operations. Most of this documentation outlines the usage of `Thread`, however you can implement your own `ParallelProcess` class and spawn it with the `ProcessManager`.

For example:

```
class MyCustomProcess extends \Weird\Processes\ParallelProcess
{
    // Define how often tick should be executed in seconds
    protected float $tickRate = 1 / 32;

    public function register()
    {
        // execute startup tasks
    }

    public function read($stdin)
    {
        while ($message = $this->readStream($stdin)) {
            // do something with messages sent from the parent process
        }
    }

    public function tick()
    {
        // do something
    }
}

// ...

$manager = ProcessManager::create()
    ->spawn(MyCustomProcess::class, processes: 5);
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

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

Recently: every ~66 days

Total

6

Last Release

648d ago

### Community

Maintainers

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

---

Top Contributors

[![jaxwilko](https://avatars.githubusercontent.com/u/31214002?v=4)](https://github.com/jaxwilko "jaxwilko (19 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jaxwilko-weird-php/health.svg)

```
[![Health](https://phpackages.com/badges/jaxwilko-weird-php/health.svg)](https://phpackages.com/packages/jaxwilko-weird-php)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.3k](/packages/illuminate-database)[laravel/octane

Supercharge your Laravel application's performance.

4.0k21.5M156](/packages/laravel-octane)[league/geotools

Geo-related tools PHP 7.3+ library

1.4k5.3M26](/packages/league-geotools)[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)

PHPackages © 2026

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