PHPackages                             marko/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. [Framework](/categories/framework)
4. /
5. marko/pubsub

ActiveMarko-module[Framework](/categories/framework)

marko/pubsub
============

Pub/sub interfaces and value objects for Marko Framework

0.7.0(3w ago)046↓90.9%2MITPHPPHP ^8.5

Since Mar 25Pushed 3w agoCompare

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

READMEChangelogDependencies (12)Versions (18)Used By (2)

marko/pubsub
============

[](#markopubsub)

Real-time publish/subscribe messaging contracts — type-hint against a stable interface and swap drivers without changing application code.

Overview
--------

[](#overview)

`marko/pubsub` provides the core contracts for publish/subscribe messaging in Marko. It defines `PublisherInterface`, `SubscriberInterface`, `Subscription`, and the `Message` value object. The package ships no driver of its own — install a driver package such as `marko/pubsub-pgsql` or `marko/pubsub-redis` to get a concrete implementation.

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

[](#installation)

```
composer require marko/pubsub
```

Usage
-----

[](#usage)

Type-hint against the interfaces in your services and let the container inject the active driver.

```
use Marko\PubSub\Message;
use Marko\PubSub\PublisherInterface;
use Marko\PubSub\SubscriberInterface;

// Publishing
$publisher->publish(
    channel: 'orders',
    message: new Message(
        channel: 'orders',
        payload: json_encode(['id' => $order->id, 'status' => 'placed']),
    ),
);

// Subscribing
$subscription = $subscriber->subscribe('orders');

foreach ($subscription as $message) {
    $data = json_decode($message->payload, true);
}

// Cancel when done
$subscription->cancel();

// Pattern subscriptions (Redis driver only)
$subscription = $subscriber->psubscribe('orders.*');
```

Configuration keys used by driver packages:

```
// config/pubsub.php
return [
    'driver' => 'redis',   // active driver
    'prefix' => '',        // optional channel prefix applied by all drivers
];
```

API Reference
-------------

[](#api-reference)

### `PublisherInterface`

[](#publisherinterface)

```
interface PublisherInterface
{
    public function publish(string $channel, Message $message): void;
}
```

### `SubscriberInterface`

[](#subscriberinterface)

```
interface SubscriberInterface
{
    public function subscribe(string ...$channels): Subscription;
    public function psubscribe(string ...$patterns): Subscription;
}
```

### `Message`

[](#message)

```
readonly class Message
{
    public function __construct(
        public string $channel,
        public string $payload,
        public ?string $pattern = null,
    ) {}
}
```

### `Subscription`

[](#subscription)

```
interface Subscription extends IteratorAggregate
{
    /** @return Generator */
    public function getIterator(): Generator;
    public function cancel(): void;
}
```

### `PubSubException`

[](#pubsubexception)

Named constructors for all failure scenarios:

Factory methodWhen thrown`connectionFailed(string $driver, string $reason)`Driver cannot connect`subscriptionFailed(string $channel, string $reason)`Subscribe call fails`publishFailed(string $channel, string $reason)`Publish call fails`patternSubscriptionNotSupported(string $driver)``psubscribe()` on a driver that does not support patternsDocumentation
-------------

[](#documentation)

Full usage, API reference, and examples: [marko/pubsub](https://marko.build/docs/packages/pubsub/)

###  Health Score

43

—

FairBetter than 90% of packages

Maintenance94

Actively maintained with recent releases

Popularity9

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity50

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

Recently: every ~15 days

Total

16

Last Release

27d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/437029?v=4)[Mark Shust](/maintainers/markshust)[@markshust](https://github.com/markshust)

---

Top Contributors

[![markshust](https://avatars.githubusercontent.com/u/437029?v=4)](https://github.com/markshust "markshust (9 commits)")

###  Code Quality

TestsPest

### Embed Badge

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

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

PHPackages © 2026

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