PHPackages                             ptrofimov/zeroevents - 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. ptrofimov/zeroevents

ActiveLibrary

ptrofimov/zeroevents
====================

Events between processes. Built on top of Illuminate\\Events and ZeroMQ

3.2(11y ago)114.0k2MITPHPPHP &gt;=5.4.0

Since Dec 7Pushed 8y ago1 watchersCompare

[ Source](https://github.com/ptrofimov/zeroevents)[ Packagist](https://packagist.org/packages/ptrofimov/zeroevents)[ RSS](/packages/ptrofimov-zeroevents/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (9)Used By (0)

zeroevents
==========

[](#zeroevents)

[![Latest Stable Version](https://camo.githubusercontent.com/24274fb1217aeb3817097171eed6307865a519430f0a1e18c42df35ebae13761/68747470733a2f2f706f7365722e707567782e6f72672f7074726f66696d6f762f7a65726f6576656e74732f762f737461626c65)](https://packagist.org/packages/ptrofimov/zeroevents) [![Total Downloads](https://camo.githubusercontent.com/19d8d11f44a3541c40f243553da39687808ea5482183ea661d6c9654f75eae55/68747470733a2f2f706f7365722e707567782e6f72672f7074726f66696d6f762f7a65726f6576656e74732f646f776e6c6f616473)](https://packagist.org/packages/ptrofimov/zeroevents) [![License](https://camo.githubusercontent.com/c76457ea5e257778bdeb9dfebe6a282b52cad6b8e13b4eba1e19de87635b2e19/68747470733a2f2f706f7365722e707567782e6f72672f7074726f66696d6f762f7a65726f6576656e74732f6c6963656e7365)](https://packagist.org/packages/ptrofimov/zeroevents) [![Build Status](https://camo.githubusercontent.com/734210ea2ecff394e1d83bb8aa482bd2c083f9be96fae04171b72d531adbe83e/68747470733a2f2f7472617669732d63692e6f72672f4f6c64656e2f7a65726f6576656e74732e7376673f6272616e63683d7472617669732d6369)](https://travis-ci.org/Olden/zeroevents)

Events between processes. Built on top of Illuminate\\Events and ZeroMQ.

It could be used for building distributed **PHP** applications and asynchronous **event** processing systems with **ZeroMQ** as transport for messages.

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

[](#installation)

Install package using [composer](https://getcomposer.org/)

```
composer require ptrofimov/zeroevents:3.*

```

Quick Introduction
------------------

[](#quick-introduction)

- 1. **In the first process:** subscribe EventListener to desired events.

```
Event::listen('my.events.*', new EventListener(['connect' => 'ipc://my.ipc']));
```

In EventListener constructor could be passed either array of options (will be merged with default options) or string (path to options for Config::get())

- 2. **In the second process:** define listeners for events. And run event service that will listen to messages on socket and fire incoming events.

```
Event::listen('my.events.*', function () {
    echo 'Catched event:', Event::firing(), PHP_EOL;
});

(new EventService)
    ->listen(new EventListener(['bind' => 'ipc://my.ipc']))
    ->run();
```

That's it. Each time the event is fired in first process, that will be transferred to the second process and be fired there as well.

EventSocket class
-----------------

[](#eventsocket-class)

EventSocket PHP class is inherited from ZMQSocket. Its supports all native methods like connect and send, plus it adds methods for sending and receiving events with ZeroMQ.

### Methods

[](#methods)

- **encode**(string *event*, array *payload*) - serialize event and payload into array of frames before sending
- event goes as string in the first frame of message
- payload is serialized in JSON(by default) and goes in the following frames of message
- encode method is used in **push** method
- **decode**(array *frames*) - unserialize event and payload from array of frames after receiving
- return array \[event, payload\]
- event is supposed to go as string in the first frame of message
- payload is supposed to go as serialized in JSON in the following frames of message
- decode method is used in **pull** method

### Connecting socket

[](#connecting-socket)

You can use usual way to connect to ZeroMQ socket via calling the constructor of ZMQSocket or, better, use **EventListener** that gives you connected socket on the base of options from config.

```
use ZeroEvents\EventSocket;

$socket = new EventSocket(new ZMQContext, ZMQ::SOCKET_PUSH);
$socket->connect('ipc:///var/tmp/test.ipc');
```

### Pushing events

[](#pushing-events)

It is recommended to listen to events that occur during sending of the message (ttl expired, out of connection) to handle them.

```
Event::listen('zeroevents.push.error', function () {
    // logging or something else
});

$socket->push('event', ['payload']);
```

EventListener class
-------------------

[](#eventlistener-class)

EventListener PHP class is supposed to be passed to event dispatcher as listener callback. It has magic method **\_\_invoke**, that is called, when an event is fired. EventListener creates EventSocket instance on-demand (lazy connection) and call method **EventSocket::push**.

```
Event::listen('my.events.*', new EventListener('my.socket.config.key'));
```

Constructor accepts either string (config key) or array of options.

### Connection options

[](#connection-options)

```
$options = [

    'example.connection' => [

        /*
         * Number of io-threads in context, default = 1
         */

        'threads' => 1,

        /*
         * Persistent context is stored over multiple requests, default = false
         */

        'is_persistent' => false,

        /*
         * Socket type
         *
         * Full list of available types http://php.net/manual/en/class.zmq.php
         * Description of sockets http://zguide.zeromq.org/page:all#toc11
         */

        'socket_type' => ZMQ::SOCKET_PUSH,

        /*
         * Default options for ZeroMQ socket
         */

        'socket_options' => [
            ZMQ::SOCKOPT_LINGER => 2000, // wait before disconnect (ms)
            ZMQ::SOCKOPT_SNDTIMEO => 2000, // send message timeout (ms)
            ZMQ::SOCKOPT_RCVTIMEO => 2000, // receive message timeout (ms)
        ],

        /*
         * Addresses to bind. Only one process can bind address
         *
         * About available transports (inproc, ipc, tcp) http://zguide.zeromq.org/page:all#toc13
         */

        'bind' => [
            'tcp://127.0.0.1:5555',
        ],

        /*
         * Addresses of sockets, the same time can be connected multiple addresses
         *
         * About available transports (inproc, ipc, tcp) http://zguide.zeromq.org/page:all#toc13
         */

        'connect' => [
            'tcp://127.0.0.1:5555',
        ],

        /*
         * Type of events to subscribe. Events masks (*) are not here supported.
         *
         * Only useful for SOCKET_SUB socket type
         */

        'subscribe' => 'my.events',

        /*
         * Send/wait confirmation after sending/receiving message
         */

        'confirmed' => false,

        /*
        * Serializer Interface through which message payload is serialized before sending
        */

        'serializer' => 'ZeroEvents\Serializers\JsonSerializer'
    ],
];
```

EventService class
------------------

[](#eventservice-class)

Class is used to listen to incoming events and fire them.

### Polling sockets

[](#polling-sockets)

EventService class is able to listen to several sockets the same time.

```
(new EventService)
    ->listen(new EventListener(['connect' => 'ipc://first.ipc']))
    ->listen(new EventListener(['connect' => 'ipc://second.ipc']))
    ->run();
```

### Idle events

[](#idle-events)

You can specify the polling time - max time that service waits for incoming events and if there are no such events, it fires **zeroevents.service.idle** event, which you can handle and execute your own code while there is no work for the service.

### System signals

[](#system-signals)

EventService class has default handler for system POSIX signals. It ignores **SIGHUP**, and gracefully stops on **SIGTERM** and **SIGINT** signals. Sure, you could define your own system signal handler.

### Stopping the service

[](#stopping-the-service)

Normally, the service is being stopped by system signal. But you could easily stop the service by firing **zeroevents.service.stop** event.

License
-------

[](#license)

Copyright (c) 2015 Petr Trofimov

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity25

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity63

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

Recently: every ~0 days

Total

8

Last Release

4105d ago

Major Versions

1.1 → 2.02015-01-04

2.0 → 3.02015-02-19

2.2 → 3.22015-02-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/7055160847368dea476b261891757010bd52eed1698560047cd49ae178730c76?d=identicon)[ptrofimov](/maintainers/ptrofimov)

---

Top Contributors

[![ptrofimov](https://avatars.githubusercontent.com/u/867178?v=4)](https://github.com/ptrofimov "ptrofimov (33 commits)")

---

Tags

laraveleventsilluminatezeromqzmq

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ptrofimov-zeroevents/health.svg)

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

###  Alternatives

[chelout/laravel-relationship-events

Missing relationship events for Laravel

5252.3M17](/packages/chelout-laravel-relationship-events)[nuwber/rabbitevents

The Nuwber RabbitEvents package

120515.8k3](/packages/nuwber-rabbitevents)[mpyw/laravel-database-advisory-lock

Advisory Locking Features of Postgres/MySQL/MariaDB on Laravel

2860.5k](/packages/mpyw-laravel-database-advisory-lock)[artificertech/laravel-relationship-events

Missing relationship events for Laravel

1218.8k](/packages/artificertech-laravel-relationship-events)[denpa/laravel-zeromq

ZeroMQ driver for Laravel

171.1k](/packages/denpa-laravel-zeromq)

PHPackages © 2026

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