PHP code example of migratorydata / migratorydata-client-reactphp
1. Go to this page and download the library: Download migratorydata/migratorydata-client-reactphp library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
migratorydata / migratorydata-client-reactphp example snippets
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";
}
}
$loop = \React\EventLoop\Factory::create();
$client = new MigratoryDataClient();
$client->setLoop($loop);
$client->setEntitlementToken("some-token");
$client->setServers(array("http://127.0.0.1:8800"));
$client->subscribe(array("/server/status"));
$client->connect();
$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());
}
});
$loop->run();
igratoryData\Client\MigratoryDataClient;
use MigratoryData\Client\MigratoryDataException;
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";
}
}
$loop = \React\EventLoop\Factory::create();
$client = new MigratoryDataClient();
$client->setEntitlementToken("some-token");
$client->setLoop($loop);
$client->setListener(new MyListener());
try {
$client->setServers(array("http://127.0.0.1:8800"));
} catch (MigratoryDataException $e) {
echo($e->getDetail());
exit(1);
}
$client->subscribe(array("/server/status"));
$client->connect();
$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());
}
});
$loop->run();
bash
php echo-time-client.php