<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
migratorydata / migratorydata-client-php example snippets
use MigratoryData\Client\MigratoryDataClient;
use MigratoryData\Client\MigratoryDataMessage;
$client = new MigratoryDataClient();
$client->setEntitlementToken("some-token");
$client->setServers(array("http://127.0.0.1:8800"));
// call connect for client API for PHP v6
$client->connect();
$message = new MigratoryDataMessage("/server/status", time());
$response = $client->publish($message);
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) {
// Exceptions with one of the error codes:
// E_INVALID_URL_LIST
// E_CLUSTER_MEMBERS_CONNECTION_FAILED
// E_ENTITLEMENT_TOKEN
// See the documentation of MigratoryDataException for more details
echo("Exception: " . $e->getDetail() . "\n");
exit(1);
}
while(true) {
$start = microtime(true);
$message = new MigratoryDataMessage("/server/status", time());
try {
$response = $client->publish($message);
} catch (MigratoryDataException $e) {
// Exception with one of the error codes:
// E_MSG_NULL
// E_MSG_FIELD_INVALID
// E_MSG_INVALID
// E_INVALID_SUBJECT
// E_INVALID_PROTOCOL
// See the documentation of MigratoryDataException for more details
echo("Exception: " . $e->getDetail() . "\n");
}
$end = microtime(true);
echo $response . ' ' . ($end - $start) . ' ms' . "\n";
sleep(1);
}
igratoryData\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 documentation 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);
}
bash
composer
bash
composer
bash
php echo-time-client.php
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.