PHPackages                             so-php/pubsub - 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. so-php/pubsub

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

so-php/pubsub
=============

Publish Subscribe pattern via php-amqplib

0.0.1-alpha(12y ago)0202PHPPHP &gt;=5.3.0

Since May 27Pushed 12y ago1 watchersCompare

[ Source](https://github.com/so-php/pubsub)[ Packagist](https://packagist.org/packages/so-php/pubsub)[ RSS](/packages/so-php-pubsub/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (2)Versions (2)Used By (2)

pubsub
======

[](#pubsub)

Publish Subscribe Pattern via php-amqplib

Avoiding Technology Lockout
---------------------------

[](#avoiding-technology-lockout)

One of the goals of ths implementation is to prevent locking out other technologies like python, ruby and java from publishing and subscribing. This is not a terribly difficult task--it just means we need to use a non-proprietary message queue (php-amqplib + rabbitmq) and a message format that isn't language specific. Hence we choose to use a json serialized data structure rather than a PHP serialized string.

That being said, there are no enforced restrictions on the content of the event params. It is up to developers to keep vigilent and be sure not to stuff anything in event parameters that is PHP or platform specific.

Message Structure
-----------------

[](#message-structure)

As stated above, the message is a plain Json string. The structure is an object with three keys (only) at the top level.

- `name` the event name
- `time` the timestamp of the event in ISO 8601. The time should be in UTC.
- `params` an object to hold event params. No imposed limits other than technical feasibility and reasonablenes. Params should be present even if empty `{}`.

```
{
    "name": "some-event-name",
    "datetime": "2005-08-15T15:52:01+0000",
    "params": {
        "any": true,
        "number": 1.3,
        "of": "foo",
        "keys": {
           "of any nesting level": "but be reasonable"
        }
    }
}

```

Usage
-----

[](#usage)

Using PubSub is pretty straight forward. Words in uppercase are values that need to be supplied/configured.

### Publishing

[](#publishing)

```
// need a channel to work with
$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$ch = $conn->channel();

$pubSub = new PubSub($ch, EXCHANGE_NAME);
$pubSub->publish('foo', array('hello'=>'world'));

```

### Publishing

[](#publishing-1)

```
// need a channel to work with
$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$ch = $conn->channel();

function doSomethingOnEvent(Event e){
   echo "Received event " . $e->getName() . " which was triggered on " . $e->getDateTime()->format('Y-m-d H:i:s') . " with the following params: " . print_r($e->getParams(),true);
}

$pubSub = new PubSub($ch, EXCHANGE_NAME);
$pubSub->subscribe('foo', 'doSomethingOnEvent');

// then wait for (and handle events)
// either:
$pubSub->wait(); // wraps $ch->wait() internally
// or directly on the channel object
$ch->wait();

```

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity44

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

Unknown

Total

1

Last Release

4421d ago

### Community

Maintainers

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

---

Top Contributors

[![jeremygiberson](https://avatars.githubusercontent.com/u/487411?v=4)](https://github.com/jeremygiberson "jeremygiberson (7 commits)")

### Embed Badge

![Health badge](/badges/so-php-pubsub/health.svg)

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

###  Alternatives

[pestphp/pest

The elegant PHP Testing Framework.

11.6k72.2M20.6k](/packages/pestphp-pest)[drupal/core-dev

require-dev dependencies from drupal/drupal; use in addition to drupal/core-recommended to run tests from drupal/core.

2022.6M343](/packages/drupal-core-dev)[ec-europa/toolkit

Toolkit packaged for Drupal projects based on Robo.

40252.8k34](/packages/ec-europa-toolkit)

PHPackages © 2026

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