PHPackages                             phpway/pubsubwp - 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. phpway/pubsubwp

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

phpway/pubsubwp
===============

Simple publish-subscribe library with ability to specify priority for subscribers

1.0(8y ago)032MITPHPPHP ^5.6 || ^7.0

Since Nov 16Pushed 6y ago1 watchersCompare

[ Source](https://github.com/phpway/pubsubwp)[ Packagist](https://packagist.org/packages/phpway/pubsubwp)[ RSS](/packages/phpway-pubsubwp/feed)WikiDiscussions master Synced 4d ago

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

Pubsub with priority
====================

[](#pubsub-with-priority)

[![Build Status](https://camo.githubusercontent.com/93a405cd7cf5c1106aea797d3b212d4f4f6de019673324b4069f92a677f5529d/68747470733a2f2f7472617669732d63692e6f72672f7068707761792f70756273756277702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/phpway/pubsubwp)

I hear you - why another pubsub library when there is already a plethora of them? I was looking for a simple PHP publish-subscribe implementation with following properties:

- simple and easy to use
- ability to set optional priority for subscribers; those with higher priority will be called first when topic is published
- ability for subscribers to stop calling following callbacks in the queue when topic is published

This simple pubsub library tries to fill in this gap.

Example of usage
----------------

[](#example-of-usage)

Create pubsub instance:

```
$pubsub = new \PubSubWP\PubSub;
```

Subscribe few callbacks to some topic:

```
$pubsub->subscribe('topic.foo', function ($event) { $event['tape'] .= 'a'; });
$pubsub->subscribe('topic.foo', function ($event) { $event['tape'] .= 'b'; });
```

You can also subscribe callback with priority. When topic is published, callbacks are sorted by this priority before they are called (higher priority callbacks will be executed first). Default priority is 0.

```
$priority = 10;
$pubsub->subscribe('topic.foo', function ($event) { $event['tape'] .= 'A'; }, $priority);
```

When topic is published via `PubSub::publish()` method, the pubsub will create an event object (inherited from `ArrayObject`) and it will start passing it through all subscribed callbacks sorted by priorities:

```
$initialEventData = ['tape' => ''];
$event = $pubsub->publish('topic.foo', $initialEventData);
```

Event's initial data can be specified in the second optional parameter. Each subscribed callback will receive this event object in the (only) parameter.

```
print $event['tape'];   // 'Aab'
```

Callback writing 'A' on tape was executed first since it has higher priority than others.

Callback can also decide to skip all other callbacks in the queue that have not been executed yet. This is done simply via calling `Event::stop()` method:

```
$pubsub->subscribe(
    'topic.foo',
    function ($event) {
        $event['tape'] .= '[STOP]';
        $event->stop();
    },
    5
);
```

This will cause skipping all callbacks with priority lower than 5:

```
$event = $pubsub->publish('topic.foo', ['tape' => '']);
print $event['tape'];   // 'A[STOP]'
```

You can also specify your own event that will be passed through the subscribed callbacks. The only requirement is that it must inherit from `PubSubWP\Event`which is the class of the default event:

```
$myEvent = new MyEvent;
$event = $pubsub->publish('topic.foo', $myEvent);
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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

3102d ago

### Community

Maintainers

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

---

Top Contributors

[![phpway](https://avatars.githubusercontent.com/u/10482389?v=4)](https://github.com/phpway "phpway (10 commits)")

---

Tags

eventspubsubprioritypublish-subscribe

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/phpway-pubsubwp/health.svg)

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

###  Alternatives

[doctrine/event-manager

The Doctrine Event Manager is a simple PHP event system that was built to be used with the various Doctrine projects.

6.1k501.1M115](/packages/doctrine-event-manager)[psr/event-dispatcher

Standard interfaces for event handling.

2.3k618.8M865](/packages/psr-event-dispatcher)[laminas/laminas-eventmanager

Trigger and listen to events within a PHP application

1.0k69.8M225](/packages/laminas-laminas-eventmanager)[simshaun/recurr

PHP library for working with recurrence rules

1.6k15.7M40](/packages/simshaun-recurr)[chelout/laravel-relationship-events

Missing relationship events for Laravel

5252.3M17](/packages/chelout-laravel-relationship-events)[tormjens/eventy

The WordPress filter/action system in Laravel

438912.9k16](/packages/tormjens-eventy)

PHPackages © 2026

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