migratorydata/migratorydata-client-php

MigratoryData Client API for PHP

5.0.1 2020-06-03 20:13 UTC

This package is not auto-updated.

Last update: 2020-07-02 12:36:08 UTC


README

Below you can find a tutorial and usage example. For more information please refer to MigratoryData Documentation 5.x.

Usage

Install the MigratoryData client library 5.x using composer:

$ composer require migratorydata/migratorydata-client-php:5.*

Create a MigratoryData client:

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

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

$client = new MigratoryDataClient(); 

Initialize the MigratoryData client:

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

Publish a message to MigratoryData server:

$message = new MigratoryDataMessage("/server/status", time());
$response = $client->publish($message);

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

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

<?php
require __DIR__ . '/vendor/autoload.php';

use MigratoryData\Client\MigratoryDataClient;
use MigratoryData\Client\MigratoryDataException;
use MigratoryData\Client\MigratoryDataMessage;

$client = new MigratoryDataClient();
$client->setEntitlementToken("some-token");

try {
    $client->setServers(array("http://127.0.0.1:8800"));
} catch (MigratoryDataException $e) {
    $ex = $e->getExceptions();
    foreach ($ex as $a) {
        echo $a->getCause() . ' - ' . $a->getDetail() . "\n";
    }
}
while(true) {
    $start = microtime(true);

    $message = new MigratoryDataMessage("/server/status", time());
    try {
        $response = $client->publish($message);
    } catch (MigratoryDataException $e) {
        echo $e->getDetail() . "\n";
        $ex = $e->getExceptions();
        foreach ($ex as $a) {
            echo $a->getCause() . ' - ' . $a->getDetail() . "\n";
        }	
    }

    $end = microtime(true);

    echo $response . ' ' . ($end - $start) . ' ms' . "\n";

    sleep(1);
}