承接 migratorydata/migratorydata-client-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

migratorydata/migratorydata-client-php

最新稳定版本:6.0.5

Composer 安装命令:

composer require migratorydata/migratorydata-client-php

包简介

MigratoryData Client API for PHP

README 文档

README

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

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-php: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-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

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 Client API for PHP V5 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 -d --name my_migratorydata -p 8800:8800 migratorydata/server:latest
<?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) {
	// 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);
} 

Example for Client API for PHP V6 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;

// 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);
} 

统计信息

  • 总下载量: 24.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2020-06-03