PHPackages                             abrouter/abrouter-php-client - 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. [Testing &amp; Quality](/categories/testing)
4. /
5. abrouter/abrouter-php-client

ActiveLibrary[Testing &amp; Quality](/categories/testing)

abrouter/abrouter-php-client
============================

AbrPHPClient :construction\_worker\_woman: is a PHP library to run ab-tests via ABRouter.

0.24.0(1y ago)624.7k—0%12LGPL-3.0-or-laterPHPPHP ^7.4 || ^8.0

Since Oct 4Pushed 1y agoCompare

[ Source](https://github.com/abrouter/abrouter-php-client)[ Packagist](https://packagist.org/packages/abrouter/abrouter-php-client)[ RSS](/packages/abrouter-abrouter-php-client/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (29)Used By (2)

PHP A/B Tests - ABRouter-php-client
===================================

[](#php-ab-tests---abrouter-php-client)

AbrPHPClient 👷‍♀️ is a PHP library to run ab-tests via ABRouter. Please, check out ABRouter main repository:

You're welcome to [visit the docs](https://docs.abrouter.com).

What is the ABRouter service ?
==============================

[](#what-is-the-abrouter-service-)

[ABRouter](https://abrouter.com) is the service to manage experiments(ab-tests). The service provides easy to manage dashboard to get experiments under control. There you can create experiments, branches and set a percentage for every branch. Then, when you're running an ab-test on PHP you will receive a perfect branch-wise response that following the rules, that you set up.

Can be also used as a feature flag or feature toggle and open-source. Available for free.

📦 Install
---------

[](#package-install)

Via composer

```
$ composer require abrouter/abrouter-php-client
```

🚀 Usage
-------

[](#rocket-usage)

Client is uses [PHP-DI](https://github.com/PHP-DI/PHP-DI) for DI. If you're uses own DI, you must to configure it in a such way as on example below. If you're not uses any DI, let's move php-di from dev-dependency to dependency:

```
$ composer require "php-di/php-di": "^6.0"
```

### Using with PHP-DI

[](#using-with-php-di)

```
use Abrouter\Client\Config\Config;
use DI\ContainerBuilder;
use Abrouter\Client\Client;

require '/app/vendor/autoload.php';

$containerBuilder = new ContainerBuilder();
$di = $containerBuilder->build();

$token = '04890788ba2c89c4ff21668c60838a00a87b1cf42c9c6b45d6aa8e11174f0d5762b16b6c09b6b822'; //you can find your token in ABRouter dashboard

$di->set(Config::class, new Config($token, 'https://abrouter.com'));
/**
 * @var Client $client
 */
$client = $di->make(Abrouter\Client\Client::class);
$userSignature = $_SERSSION['userId'] ?? uniqid();
$experimentId = 'button_color';//experiment id is also there

$runExperimentResult = $client->experiments()->run($userSignature, $experimentId);
$experimentId = $runExperimentResult->getExperimentId(); //form-color
$branchId = $runExperimentResult->getBranchId(); //red
echo 'Hello';
```

You can create an experiment and get your token and id of experiment on [ABRouter](https://abrouter.com) or just read the [docs](https://abrouter.com/en/docs).

Sending the stats
-----------------

[](#sending-the-stats)

```
use Abrouter\Client\Config\Config;
use DI\ContainerBuilder;
use Abrouter\Client\Client;
use Abrouter\Client\Builders\StatEventBuilder;

require '/app/vendor/autoload.php';

$userSignature = $_SERSSION['userId'] ?? uniqid();

$containerBuilder = new ContainerBuilder();
$di = $containerBuilder->build();

/**
 * @var Client $client
 */
$client = $di->make(Abrouter\Client\Client::class); // using PHP-DI

$eventBuilder = $this->getContainer()->make(StatEventBuilder::class);

//sending button_click event as button_click+1
$client->statistics()->sendEvent(
    $eventBuilder
        ->incremental()
        ->event('button_click')
        ->setUserId($userSignature)
        ->build()
);

// sending purchase event with purchase amount
$client->statistics()->sendEvent(
    $eventBuilder
        ->summarize()
        ->event('purchase')
        ->setValue(30)
        ->setUserId($userSignature)
        ->build()
);
```

For additional details of sending events please see StatEventBuilder class.

Parallel running
----------------

[](#parallel-running)

Parallel running is a mode which allows you to run the experiments asynchronous. Main things to make it works are configuring KvStorage and TaskManager. KvStorage and TaskManager are using Redis to store data and tasks.

ABRouter php client has built-in KvStorage and TaskManager, but you can make your own implementation and replace it via DI and contracts. We're highly recommend you to use built-in solution. The implementation is completely tested and works well. Using Parallel running gives you a great growth in speed.

The config for parallel running is a bit different from the default config.

### Configuration

[](#configuration)

```
use Abrouter\Client\Config\Config;
use DI\ContainerBuilder;
use Abrouter\Client\Client;
use Abrouter\Client\Config\RedisConfig;
use Abrouter\Client\Contracts\KvStorageContract;
use Abrouter\Client\DB\RedisConnection;
use Abrouter\Client\Services\KvStorage\KvStorage;
use Abrouter\Client\Services\TaskManager\TaskManager;

require '/app/vendor/autoload.php';

$containerBuilder = new ContainerBuilder();
$di = $containerBuilder->build();

$redisConfig = new RedisConfig(
    $_SERVER['REDIS_HOST'] ?? 'redis',
    6379,
    '',
    '',
    ''
);

$host = 'https://abrouter.com';
$token = uniqid();

$config = new Config(
    $token,
    $host,
);
$config->setRedisConfig($redisConfig);
$container->set(Config::class, $config);

$kvStorage = $container->make(KvStorage::class);
$container->make(KvStorage::class);
$container->set(
    KvStorageContract::class,
    $kvStorage
);

$config->setKvStorageConfig($kvStorage);
$container->set(Config::class, $config);
$taskManager = $container->make(TaskManager::class);

$config->setParallelRunConfig(new ParallelRunConfig(true, $taskManager));
```

### Worker

[](#worker)

Worker is a supervisor config which running the process which handles your tasks. Make sure supervisor is installed on your machine. The example of supervisor config is located in worker/worker.conf. Please, configure the worker.php before running the supervisor config. You have to put the same configuration of the client there as in your main application. Copy supervisor config to the specific folder which specified in etc/init.d/supervisord.conf. And, please don't forget to adjust the path of worker.php aligned to your application base directory.

✅ Testing
---------

[](#white_check_mark-testing)

Requires docker-compose and docker installed.

```
$ make up
$ make test-run
```

🔧 Contributing
--------------

[](#wrench-contributing)

Please feel free to fork and sending Pull Requests. This project follows [Semantic Versioning 2](http://semver.org) and [PSR-2](http://www.php-fig.org/psr/psr-2/).

📄 License
---------

[](#page_facing_up-license)

GPL3. Please see [License File](LICENSE) for more information.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance34

Infrequent updates — may be unmaintained

Popularity32

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.4% 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 ~39 days

Recently: every ~177 days

Total

27

Last Release

656d ago

PHP version history (3 changes)0.1.0PHP ^5.5 || ^7.0

0.2.0PHP ^5.5 || ^7.0 || ^8.0

0.5.0PHP ^7.4 || ^8.0

### Community

Maintainers

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

---

Top Contributors

[![yatsenkolesh](https://avatars.githubusercontent.com/u/20239433?v=4)](https://github.com/yatsenkolesh "yatsenkolesh (71 commits)")[![Omelya](https://avatars.githubusercontent.com/u/82599515?v=4)](https://github.com/Omelya "Omelya (4 commits)")[![ziming](https://avatars.githubusercontent.com/u/679513?v=4)](https://github.com/ziming "ziming (1 commits)")

---

Tags

ab-testingab-testing-phpab-testsexperimentsexperiments-phpfeaturefeature-flagsfeature-togglefeature-toggle-php

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/abrouter-abrouter-php-client/health.svg)

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

###  Alternatives

[magento/magento2-functional-testing-framework

Magento2 Functional Testing Framework

15511.5M30](/packages/magento-magento2-functional-testing-framework)[ikwattro/guzzle-stereo

Guzzle Recorder for recording Request/Responses and replay them back in a Mock

782.6k1](/packages/ikwattro-guzzle-stereo)

PHPackages © 2026

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