PHPackages                             apex/cluster - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. apex/cluster

ActivePackage[Utility &amp; Helpers](/categories/utility)

apex/cluster
============

Load Balancer / Router for Horizontal Scaling

2.0.3(2y ago)119211MITPHPPHP &gt;=8.0

Since Feb 16Pushed 2y ago2 watchersCompare

[ Source](https://github.com/apexpl/cluster)[ Packagist](https://packagist.org/packages/apex/cluster)[ Docs](https://apexpl.io)[ RSS](/packages/apex-cluster/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (8)Versions (15)Used By (1)

Cluster - Load Balancer / Router for Horizontal Scaling
=======================================================

[](#cluster---load-balancer--router-for-horizontal-scaling)

Cluster provides a simple yet intuitive interface to implement horizontal scaling across your application via RabbitMQ or any message broker. With the local message broker, easily develop your software with horizontal scaling fully implemented while running on one server, and split into multiple server instances within minutes when necessary. It supports:

- General round robin and routing of designated messages to specific server instances.
- One-way queued messages, two-way RPC calls, and system wide broadcasts.
- Parameter / header based routing.
- Easy to configure YAML router file.
- Optional centralized redis storage of router configuration for maintainability across server instances.
- Standardized immutable request and response objects for ease-of-use and interopability.
- Front-end handlers for streamlined communication back to front-end servers allowing execution of events to the client side (eg. set template variables, et al).
- Timeout and message preparation handlers, plus concurrency settings.
- Interchangeable with any other message broker including the ability to easily implement your own.
- Includes local message broker, allowing implementation of logic for horizontal scaling while remaining on one server instance.
- Optional auto-routing allowing messages to be automatically routed to correct class and method that correlates to named routing key.

Table of Contents
-----------------

[](#table-of-contents)

1. [Cluster class / Container Definitions](https://github.com/apexpl/cluster/blob/master/docs/cluster.md)
2. [Router Overview](https://github.com/apexpl/cluster/blob/master/docs/router.md)
    1. [Adding Routes in PHP](https://github.com/apexpl/cluster/blob/master/docs/router_php.md)
    2. [Router YAML Configuration File](https://github.com/apexpl/cluster/blob/master/docs/router_yaml.md)
    3. [Auto Routing](https://github.com/apexpl/cluster/blob/master/docs/router_auto.md)
    4. [Parameter Based Routing](https://github.com/apexpl/cluster/blob/master/docs/router_params.md)
    5. [Enable redis Autoloading](https://github.com/apexpl/cluster/blob/master/docs/redis.md)
3. Message Handling
    1. [Listen / Consume Messages](https://github.com/apexpl/cluster/blob/master/docs/listen.md)
    2. [Dispatch Messages](https://github.com/apexpl/cluster/blob/master/docs/dispatch.md)
    3. [Fetch Messages from Queues](https://github.com/apexpl/cluster/blob/master/docs/fetch.md)
4. Messages
    1. [Message Requests](https://github.com/apexpl/cluster/blob/master/docs/message_requests.md)
    2. [Message Responses](https://github.com/apexpl/cluster/blob/master/docs/message_responses.md)
5. [Front-End Handlers](https://github.com/apexpl/cluster/blob/master/docs/fe_handlers.md)

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

[](#installation)

Install via Composer with:

> `composer require apex/cluster`

Basic Usage
-----------

[](#basic-usage)

Please see the /examples/ directory for more in-depth examples.

**Save Math.php Class**

```
namespace App;

class Math {

    public function add(MessageRequestInterface $msg)
    {
        list($x, $y) = $msg->getParams();
        return ($x + $y);
    }
}
```

**Define Listener**

```
use Apex\Cluster\Cluster;
use Apex\Cluster\Listener;
use Apex\Cluster\Brokers\RabbitMQ;

// Start cluster
$cluster = new Cluster('app1');
$cluster->setBroker(new RabbitMQ('localhost', 5672, 'guest', 'guest'));
$cluster->addRoute('basic.math.*', App\Math::class);

// Start listener
$listener = new Listener();
$listener->listen();
```

**Define Dispatcher**

```
use Apex\Cluster\Dispatcher;
use Apex\Cluster\Message\MessageRequest;

// Define message
$msg = new MessageRequest('basic.math.add', 6, 9);

// Dispatch message
$dispatcher = new Dispatcher('web1');
$sum = $dispatcher->dispatch($msg)->getResponse();

// Print result
echo "Sum is: $sum\n";
```

Follow Apex
-----------

[](#follow-apex)

Loads of good things coming shortly including new quality open source packages, more advanced articles / tutorials that go over down to earth useful topics, et al. Stay informed by joining the [mailing list](https://apexpl.io/) on our web site, or follow along on Twitter at [@mdizak1](https://twitter.com/mdizak1).

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 83.3% 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 ~75 days

Recently: every ~172 days

Total

14

Last Release

933d ago

Major Versions

0.1.9 → 2.02022-01-30

PHP version history (2 changes)0.1PHP &gt;=8.0.0

2.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/4fe486d2ed7db571c0519bb0d52b08b5e953a911936e87331e736a381ef96f29?d=identicon)[apex](/maintainers/apex)

---

Top Contributors

[![mdizak](https://avatars.githubusercontent.com/u/59886259?v=4)](https://github.com/mdizak "mdizak (15 commits)")[![apexpl](https://avatars.githubusercontent.com/u/56146521?v=4)](https://github.com/apexpl "apexpl (3 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/apex-cluster/health.svg)

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

###  Alternatives

[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[magento/community-edition

Magento 2 (Open Source)

12.1k52.1k10](/packages/magento-community-edition)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

595.2M386](/packages/shopware-core)[wheelpros/fitment-platform-api

Magento 2 (Open Source)

12.1k1.2k](/packages/wheelpros-fitment-platform-api)[cognesy/instructor-php

The complete AI toolkit for PHP: unified LLM API, structured outputs, agents, and coding agent control

310107.9k1](/packages/cognesy-instructor-php)

PHPackages © 2026

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