PHPackages                             gigi/event-request-response - 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. [Queues &amp; Workers](/categories/queues)
4. /
5. gigi/event-request-response

ActiveLibrary[Queues &amp; Workers](/categories/queues)

gigi/event-request-response
===========================

Allows to publish messages and getting response from each subscriber

1.0.1(10y ago)038MITPHP

Since Feb 16Pushed 8y ago1 watchersCompare

[ Source](https://github.com/gigi/event-request-response)[ Packagist](https://packagist.org/packages/gigi/event-request-response)[ RSS](/packages/gigi-event-request-response/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (3)Used By (0)

Overview
========

[](#overview)

Small Subscriber/Publisher messaging system.

Package implements One-way Message Exchange Pattern and Request-Reply Message Exchange Pattern.

Requirement
-----------

[](#requirement)

This library package requires PHP 5.4 or later.

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

[](#installation)

`$ composer require gigi/event-request-response`

Usage
-----

[](#usage)

Create Messenger instance (singleton)

```
use gigi\events\classes\Messenger;

$handler = Messenger::getInstance();
```

Subscribe to messages

```
$handler->subscribe('message.test', function ($message) {
    // do something with message
    // stops further message processing
    $message->setIsHandled(true);

    // optionally return mixed response
    // Will be accessible in reply object (Message::getData())
    return 'Data to return';
});
```

Create message

```
use gigi\events\classes\Message;

$message = new Message('message.test', 'Mixed data to send');
```

Use one of three methods to publish $message

```
// one-way notifier
$handler->request($message);
```

```
// request-response notifier
// Returns array of Messages
$result = $handler->requestReply($message);
```

```
// request-response notifier
// Returns only first reply (Message object)
// Use if Your don't care of who can return an answer
// for example if you want to get list of all users ('users.get.all')
// or you know for sure that only one subscriber listening

$result = $handler->requestFirstReply($message);
```

For detailed usage see `examples/singleton.php`.

If singleton makes you cry or your project has own dependency injection container inject `gigi\classes\MessageHandler` to new instances of `gigi\classes\Publisher` and `gigi\classes\Subscriber`. See `examples/di.php`

Usage with Yii2 Framework
-------------------------

[](#usage-with-yii2-framework)

Add Publisher and Subscriber components to config (config/web.php)

```
return [
    ...
    'components' => [
        ...
        'subscriber' => 'gigi\events\classes\Subscriber',
        'publisher'  => 'gigi\events\classes\Publisher',
        ...

```

Add `gigi\events\classes\MessageHandlerInterface` to DI container. For more information about Yii2 DI container see

```
\Yii::$container->setSingleton(
    'gigi\events\interfaces\MessageHandlerInterface',
    'gigi\events\classes\MessageHandler'
);

```

**Subscribing for event:**

```
\Yii::$app->get('subscriber')->subscribe($event, $handler);

```

**Publishing:**

```
...
use gigi\events\classes\Message;
...

/** @var \gigi\events\interfaces\MessageInterface $message */
$message = new Message($messageName, $data);

// async
\Yii::$app->get('publisher')->request($message);

// all replies
\Yii::$app->get('publisher')->requestReply($message);

// first reply
\Yii::$app->get('publisher')->requestFirstReply($message);

```

Or implement you own classes for interfaces...

Enjoy :)

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity64

Established project with proven stability

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

Total

2

Last Release

3786d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8811270?v=4)[Alexey](/maintainers/gigi)[@gigi](https://github.com/gigi)

---

Top Contributors

[![gigi](https://avatars.githubusercontent.com/u/8811270?v=4)](https://github.com/gigi "gigi (8 commits)")

---

Tags

responserequestmessageeventspublishsubscribe

### Embed Badge

![Health badge](/badges/gigi-event-request-response/health.svg)

```
[![Health](https://phpackages.com/badges/gigi-event-request-response/health.svg)](https://phpackages.com/packages/gigi-event-request-response)
```

###  Alternatives

[guzzlehttp/psr7

PSR-7 message implementation that also provides common utility methods

7.9k1.1B3.8k](/packages/guzzlehttp-psr7)[psr/http-factory

PSR-17: Common interfaces for PSR-7 HTTP message factories

1.9k728.6M2.5k](/packages/psr-http-factory)[basis-company/nats

nats jetstream client for php

204418.3k32](/packages/basis-company-nats)[nuwber/rabbitevents

The Nuwber RabbitEvents package

119525.8k4](/packages/nuwber-rabbitevents)[aplus/http

Aplus Framework HTTP Library

2371.6M10](/packages/aplus-http)[contributte/psr7-http-message

PSR-7 (HTTP Message Interface) to Nette Framework

233.0M9](/packages/contributte-psr7-http-message)

PHPackages © 2026

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