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

ActiveLibrary

sevenlinx/pubsub-php
====================

PubSub in PHP from Seven LinX Tech

013PHP

Since Apr 22Pushed 5y ago1 watchersCompare

[ Source](https://github.com/seven-linx-incorporated/pubsub-php)[ Packagist](https://packagist.org/packages/sevenlinx/pubsub-php)[ RSS](/packages/sevenlinx-pubsub-php/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (1)Used By (0)

PubSub (PHP)
============

[](#pubsub-php)

---

Requirements
------------

[](#requirements)

- PHP `^8.0`

---

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

[](#installation)

```
composer require sevenlinx/pubsub-php
```

---

Driver
------

[](#driver)

Implement your own driver with `\SevenLinX\PubSub\PubSubDriverInterface`

Example:

```
use SevenLinX\PubSub\Contracts\ChannelContract;
use SevenLinX\PubSub\Contracts\HasPriorityHandler;
use SevenLinX\PubSub\Contracts\MessageContract;
use SevenLinX\PubSub\PubSubDriverInterface;

final class MyOwnPubSubDriver implements PubSubDriverInterface
{
    public function publish(ChannelContract $channel, MessageContract $message): void
    {
        // How to publish message
    }

    public function publishBatch(ChannelContract $channel, MessageContract ...$messages): void
    {
        // The usual loop
        foreach ($messages as $message) {
            $this->publish($channel, $message);
        }
    }

    public function subscribe(ChannelContract $channel, callable $handler): void
    {
        // What to do when someone publish a message.
    }
}
```

Subscribe
---------

[](#subscribe)

Subscribe to a message.

Example:

```
$driver = new MyOwnPubSubDriver();
$channel = new MyOwnChannel();

// Using anonymous function
$driver->subscribe($channel, function ($message) {
    // Do whatever you want.
});
// Using class with __invoke method
$driver->subscribe($channel, new MyOwnHandler());
```

Publish
-------

[](#publish)

Publish a single message

Example:

```
...

$driver->publish($channel, new MyOwnMessage());
```

You can also publish multiple or in batch

```
...
$driver->publishBatch($channel, new MyOwnMessage(), new MyOtherMessage(), new GenericMessage());
```

Payload
-------

[](#payload)

You can create your own payload by implementing `\SevenLinX\PubSub\Contracts\PayloadContract`

Example:

```
use SevenLinX\PubSub\Contracts\PayloadContract;

final class Payload implements PayloadContract
{
    public function __construct(private string $message)
    {
    }

    public function getChannel() : string
    {
        return 'channel';
    }

    public function payload() : mixed
    {
        return serialize($this->message);
    }
}
```

You can pass this on your `callable` handler

```
use SevenLinX\PubSub\Contracts\ChannelContract;

...
public function subscribe(ChannelContract $channel, callable $handler): void
{
    $handler(new Payload('message'));
}
```

Generics
--------

[](#generics)

You can use generics for Channel, Message and Payload

```
use SevenLinX\PubSub\Generics\GenericChannel;use SevenLinX\PubSub\Generics\GenericMessage;

...
$driver->publish(new GenericChannel('my-own-channel'), new GenericMessage('my-own-message'));
//
```

---

Example
-------

[](#example)

You can the example in `example/` directory or run:

```
php example/example.php
```

---

Testing
-------

[](#testing)

Just run:

```
composer run testing
```

---

###### Created under [Seven LinX Incorporated](https://sevenlinx.tech/)

[](#created-under-seven-linx-incorporated)

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 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.

### Community

Maintainers

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

---

Top Contributors

[![jayaregalinada](https://avatars.githubusercontent.com/u/1170288?v=4)](https://github.com/jayaregalinada "jayaregalinada (6 commits)")

### Embed Badge

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

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

PHPackages © 2026

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