The API package is hosted on packagist.org.

Usage

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

composer require migratorydata/migratorydata-client-php:6.*

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"));

// call connect for client API for PHP v6
$client->connect();

Publish a message to MigratoryData server:

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

Example client application

The client application connects to the MigratoryData server deployed at localhost:8800 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.

docker pull migratorydata/server:latest
docker run --platform linux/amd64 -d --name my_migratorydata -p 8800:8800 migratorydata/server:latest

Copy the code below to a file named echo-time-client.php:

<?php

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

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

// Create a MigratoryData client
$client = new MigratoryDataClient();

try 
{
	// Attach the entitlement token to the client.
	$client->setEntitlementToken("some-token");

	// Connect to a MigratoryData server
	$client->setServers(array("http://127.0.0.1:8800"));
	$client->connect();
} 
catch (MigratoryDataException $e) 
{
	// Exceptions with one of the error codes: 
	//		E_INVALID_URL_LIST
	//		E_CLUSTER_MEMBERS_CONNECTION_FAILED
	//		E_ENTITLEMENT_TOKEN
	//		E_RUNNING
	//      E_CONNECTION_DENY
	// See the documenation of MigratoryDataException for more details
	echo("Exception: " . $e->getDetail() . "\n");
	exit(1);
}

while (true) 
{
	// Publish a message
	try 
	{
        $message = new MigratoryDataMessage("/server/status", time());
        $response = $client->publish($message);
		echo("Got response: " . $response . "\n");
	} 
	catch (MigratoryDataException $e) 
	{
		// Exception with one of the error codes:
        //		E_NOT_CONNECTED
		//		E_MSG_NULL
		//		E_MSG_INVALID
		//		E_INVALID_SUBJECT
		//		E_INVALID_PROTOCOL
		// See the documentation of MigratoryDataException for more details
		echo("Exception: " . $e->getDetail() . "\n");
	}
	
	sleep(1);
} 

Next, run the application using command:

php echo-time-client.php

To test the application, connect to the MigratoryData server via browser at http://localhost:8800 and go to Debug Console. Subscribe to subject /server/status and see if the Debug Console is receiving messages from example.