PHPackages                             jgswift/bubblr - 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. [Queues &amp; Workers](/categories/queues)
4. /
5. jgswift/bubblr

ActiveLibrary[Queues &amp; Workers](/categories/queues)

jgswift/bubblr
==============

Asynchronous cooperative task scheduler

0.1.5(11y ago)040MITPHPPHP &gt;=5.5

Since Oct 5Pushed 11y ago1 watchersCompare

[ Source](https://github.com/jgswift/bubblr)[ Packagist](https://packagist.org/packages/jgswift/bubblr)[ RSS](/packages/jgswift-bubblr/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (6)Dependencies (3)Versions (7)Used By (0)

bubblr
======

[](#bubblr)

PHP 5.5+ asynchronous cooperative task scheduler

[![Build Status](https://camo.githubusercontent.com/16898e56f06a00e915645693198231478eb0e455667125b301d15c923a5e4e01/68747470733a2f2f7472617669732d63692e6f72672f6a6773776966742f627562626c722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/jgswift/bubblr)[![Latest Stable Version](https://camo.githubusercontent.com/002bd30331da59471bde6119c7ba367c8af1c1fd2626edf79de1fcc708f7e1ac/68747470733a2f2f706f7365722e707567782e6f72672f6a6773776966742f627562626c722f762f737461626c652e737667)](https://packagist.org/packages/jgswift/bubblr)[![License](https://camo.githubusercontent.com/625854b0e3ccec941c26e5c221d30cdcba84d7f6607565d9c1150e51816f7108/68747470733a2f2f706f7365722e707567782e6f72672f6a6773776966742f627562626c722f6c6963656e73652e737667)](https://packagist.org/packages/jgswift/bubblr)

Description
-----------

[](#description)

bubblr is a lightweight component that allows for cooperative multitasking without needing to understand generators or requiring code modification. bubblr allows multitasking using both functional and imperative programming paradigms.

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

[](#installation)

Install via cli using [composer](https://getcomposer.org/):

```
php composer.phar require jgswift/bubblr:0.1.*
```

Install via composer.json using [composer](https://getcomposer.org/):

```
{
    "require": {
        "jgswift/bubblr": "0.1.*"
    }
}
```

Dependency
----------

[](#dependency)

- php 5.5+
- [jgswift/observr](https://github.com/jgswift/observr)
- [react/promise](https://github.com/reactphp/promise)

Usage
-----

[](#usage)

### Coroutine (Bubble)

[](#coroutine-bubble)

Coroutines, or Bubbles (as they are referred to in this package) are units of work which are queued and executed. Any function or method can be wrapped by a coroutine to allow easy multitasking with minimal overhead.

#### BubbleInterface (abbr.)

[](#bubbleinterface-abbr)

```
interface BubbleInterface extends EventInterface, EventAwareInterface {

    public function getResult();

    public function setContext($context);

    public function resume(SpoutInterface $spout);

    public function suspend(SpoutInterface $spout);
}
```

### Spouts

[](#spouts)

Spouts act as the scheduler queue to handle coroutine execution.
This is conceptually similar to a thread but must be differentiated as coroutines are executed in sequence. Coroutines may yield execution priority back to the spout, therein allowing other tasks to execute instead. For more information, [Nikita Popov](https://github.com/nikic) authored a [fairly comprehesive introduction](https://nikic.github.io/2012/12/22/Cooperative-multitasking-using-coroutines-in-PHP.html) to the subject of cooperative multitasking in PHP.

#### SpoutInterface (abbr.)

[](#spoutinterface-abbr)

```
interface SpoutInterface extends BubblerAwareInterface {

    public function push(BubbleInterface $bubble);

    public function pop();

    public function invoke(BubbleInterface $bubble);

    public function suspend();

    public function resume();
}
```

### Core Bubbler

[](#core-bubbler)

The core bubbler is the primary application that handles the creation and scheduling of spouts.

Coroutines, spouts, and the core are all open to modification using the globally aliased API.

#### BubblerInterface (abbr.)

[](#bubblerinterface-abbr)

```
interface BubblerInterface {

    public function execute($bubble = null);

    public function attach(SpoutInterface $spout);

    public function detach(SpoutInterface $spout);

    public function resume();

    public function suspend();

    public function getSpout();
}
```

### Simple example (returning values)

[](#simple-example-returning-values)

```
$hello = bubblr\async(function() {
    return 'hello world';
});

echo $hello(); // 'hello world'
```

### Scheduling existing methods

[](#scheduling-existing-methods)

```
function hello() {
    return 'hello world';
}

$hello = bubblr\async('hello');

echo $hello(); // 'hello world'
```

### Rescheduling during long-running task

[](#rescheduling-during-long-running-task)

```
$fib = bubblr\async(function($num) {
    $n1 = 0; $n2 = 1; $n3 = 1;
    for ($i = 2; $i < $num; ++$i) {
        $n3 = $n1 + $n2;
        $n1 = $n2;
        $n2 = $n3;
        // every 50 iterations this bubble will suspend and allow other waiting bubbles to execute
        if (!($i % 50)) {
              bubblr\reschedule();
        }
    }
    return $n3;
});

echo is_infinite($fib(3000)); // true
```

### Scheduling multiple coroutines at once

[](#scheduling-multiple-coroutines-at-once)

```
function hello() {
    return 'hello';
}

function world() {
    return 'world';
}

$results = bubblr\asyncAll([
    'hello',
    'world'
]);

var_dump($results); // Array ['hello','world']
```

### Throwing and handling exceptions

[](#throwing-and-handling-exceptions)

```
$addition = bubblr\async(function($a,$b) {
    if(!is_numeric($a) || !is_numeric($b)) {
        throw new \InvalidArgumentException();
    }

    return $a + $b;
});

try {
    $addition('bar',5);
} catch(\InvalidArgumentException $e) {
    echo 'Invalid argument';
}
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

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

Total

6

Last Release

4169d ago

### Community

Maintainers

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

---

Top Contributors

[![jgswift](https://avatars.githubusercontent.com/u/661738?v=4)](https://github.com/jgswift "jgswift (17 commits)")

---

Tags

phpasyncscheduler

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jgswift-bubblr/health.svg)

```
[![Health](https://phpackages.com/badges/jgswift-bubblr/health.svg)](https://phpackages.com/packages/jgswift-bubblr)
```

###  Alternatives

[revolt/event-loop

Rock-solid event loop for concurrent PHP applications.

91943.6M138](/packages/revolt-event-loop)[league/geotools

Geo-related tools PHP 7.3+ library

1.4k5.3M26](/packages/league-geotools)[toin0u/geotools

Geo-related tools PHP 7.3+ library

1.4k1.3k](/packages/toin0u-geotools)[clue/docker-react

Async, event-driven access to the Docker Engine API, built on top of ReactPHP.

113154.9k1](/packages/clue-docker-react)[orisai/scheduler

Cron job scheduler - with locks, parallelism and more

4037.1k4](/packages/orisai-scheduler)

PHPackages © 2026

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