PHPackages                             marko/pubsub-pgsql - 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-pgsql

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

marko/pubsub-pgsql
==================

PostgreSQL pub/sub driver for Marko Framework

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

Since Mar 25Pushed 3w agoCompare

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

READMEChangelogDependencies (20)Versions (18)Used By (0)

marko/pubsub-pgsql
==================

[](#markopubsub-pgsql)

Zero-infrastructure pub/sub via PostgreSQL LISTEN/NOTIFY -- real-time messaging using the database you already have, no Redis required.

Overview
--------

[](#overview)

`marko/pubsub-pgsql` implements the `marko/pubsub` contracts using PostgreSQL's native LISTEN/NOTIFY mechanism. `PgSqlPublisher` issues `NOTIFY` and `PgSqlSubscriber` issues `LISTEN` over a persistent async connection powered by `amphp/postgres`. Because PostgreSQL is already a common dependency, this driver lets you add real-time messaging with no additional infrastructure.

Note: PostgreSQL does not support pattern-based subscriptions. Calling `psubscribe()` throws `PubSubException`. Use `marko/pubsub-redis` if you need pattern matching.

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

[](#installation)

```
composer require marko/pubsub-pgsql
```

This automatically installs `marko/pubsub` and `marko/amphp`.

Usage
-----

[](#usage)

The module binding wires `PublisherInterface` → `PgSqlPublisher` and `SubscriberInterface` → `PgSqlSubscriber` automatically. Type-hint against the interfaces in your services.

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

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

// Subscribing -- issues a PostgreSQL LISTEN
$subscription = $subscriber->subscribe('orders');

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

$subscription->cancel();
```

Publish configuration in `config/pubsub-pgsql.php`:

```
return [
    'host'     => '127.0.0.1',
    'port'     => 5432,
    'user'     => 'postgres',
    'password' => '',
    'database' => 'app',
];
```

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

[](#api-reference)

### `PgSqlPublisher`

[](#pgsqlpublisher)

Implements `PublisherInterface`. Applies the configured channel prefix and issues a PostgreSQL `NOTIFY`.

```
public function publish(string $channel, Message $message): void;
```

### `PgSqlSubscriber`

[](#pgsqlsubscriber)

Implements `SubscriberInterface`. Applies the configured channel prefix and issues a PostgreSQL `LISTEN` for each channel.

```
public function subscribe(string ...$channels): Subscription;
public function psubscribe(string ...$patterns): Subscription; // throws PubSubException
```

### `PgSqlSubscription`

[](#pgsqlsubscription)

Iterates incoming `NOTIFY` payloads as `Message` instances. Implements `Subscription` (`IteratorAggregate`).

```
public function getIterator(): Generator; // yields Message
public function cancel(): void;
```

### `PgSqlPubSubConnection`

[](#pgsqlpubsubconnection)

Manages the persistent `amphp/postgres` connection used by both the publisher and subscriber.

Documentation
-------------

[](#documentation)

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

###  Health Score

42

—

FairBetter than 89% of packages

Maintenance94

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community6

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 ~13 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 (8 commits)")

###  Code Quality

TestsPest

### Embed Badge

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

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

PHPackages © 2026

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