PHPackages                             migratorydata/migratorydata-client-reactphp - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. migratorydata/migratorydata-client-reactphp

ActiveLibrary[HTTP &amp; Networking](/categories/http)

migratorydata/migratorydata-client-reactphp
===========================================

MigratoryData Client API for React PHP

6.0.8(1y ago)0298proprietaryPHPPHP &gt;=7.0.0

Since Jul 6Pushed 1y ago1 watchersCompare

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

READMEChangelog (4)Dependencies (2)Versions (10)Used By (0)

MigratoryData Client for ReactPHP 5.x &amp; 6.x
===============================================

[](#migratorydata-client-for-reactphp-5x--6x)

Below you can find a tutorial and usage example. For more information please refer to [MigratoryData Documentation 6.x](https://migratorydata.com/docs/client-api/reactphp/).

Usage
-----

[](#usage)

Install the MigratoryData client library **5.x** using composer (MigratoryData client version 5 can be used with MigratoryData Server 5.0.\*):

```
composer require migratorydata/migratorydata-client-reactphp:5.*
```

Install the MigratoryData client library **6.x** using composer (MigratoryData client version 6 can be used with the MigratoryData server 6.0.1 or later):

```
composer require migratorydata/migratorydata-client-reactphp:6.*
```

Import classes and define MigratoryData callback listener:

```
require __DIR__ . '/vendor/autoload.php';

use MigratoryData\Client\MigratoryDataClient;
use MigratoryData\Client\MigratoryDataMessage;
use MigratoryData\Client\MigratoryDataListener;

class MyListener implements MigratoryDataListener
{
    public function onMessage($message)
    {
        echo "Got message: " . $message . "\n";
    }

    public function onStatus($status, $info)
    {
        echo "Got status: " . $status . " - " . $info . "\n";
    }
}
```

Create the event loop:

```
$loop = \React\EventLoop\Factory::create();
```

Create a MigratoryData client and attach the event loop:

```
$client = new MigratoryDataClient();
$client->setLoop($loop);
```

Initialize and connect the MigratoryData client:

```
$client->setEntitlementToken("some-token");
$client->setServers(array("http://127.0.0.1:8800"));

$client->subscribe(array("/server/status"));

$client->connect();
```

Publish a message every second to MigratoryData server:

```
$loop->addPeriodicTimer(1, function () use ($client) {
    try {
        $client->publish(new MigratoryDataMessage("/server/status", "Msg " . time(), "closure-" . time()));
    } catch (MigratoryDataException $e) {
        echo($e->getDetail());
        echo($e->getCause());
    }
});
```

Start the event loop:

```
$loop->run();
```

Example client application
--------------------------

[](#example-client-application)

Copy the code below to a file named `echo-time-client.php` and run it using the following command:

```
php echo-time-client.php
```

Example for PHP React Client API

The client application connects to the MigratoryData server deployed at `localhost:8800` subscribes and publishes a message every second on the subject `/server/status`.

If you don't have a MigratoryData server installed on your machine but there is docker installed you can run the following command to start MigratoryData server, otherwise you can download and install the latest version for your os from [here](https://migratorydata.com/downloads/migratorydata-6/).

```
docker pull migratorydata/server:latest
docker run -d --name my_migratorydata -p 8800:8800 migratorydata/server:latest
```

```
