Inheritance: extends BaseAmqp
Beispiel #1
0
<?php

require_once '../../config/config.php';
require_once '../../lib/Thumper/RpcClient.php';
require_once '../../lib/php-amqplib/amqp.inc';
$start = time();
$client = new RpcClient(HOST, PORT, USER, PASS, VHOST);
$client->initClient();
$client->addRequest($argv[1], 'charcount', 'charcount');
//charcount is the request identifier
$client->addRequest(serialize(array('min' => 0, 'max' => (int) $argv[2])), 'random-int', 'random-int');
//random-int is the request identifier
echo "Waiting for replies…\n";
$replies = $client->getReplies();
var_dump($replies);
echo "Total time: ", time() - $start, "\n";
Beispiel #2
0
<?php

/**
 * Created by linzl
 * User: linzl<*****@*****.**>
 * Date: 15/1/27
 * Time: 下午2:55
 */
date_default_timezone_set('PRC');
include_once "Clients/RpcClient.php";
$address_array = array('tcp://127.0.0.1:2015', 'tcp://127.0.0.1:2015');
// 配置服务端列表
RpcClient::config($address_array);
$uid = 567;
// User对应applications/JsonRpc/Services/User.php 中的User类
$user_client = RpcClient::instance('User');
$ret_sync = $user_client->test();
print_r($ret_sync);
exit;
// getInfoByUid对应User类中的getInfoByUid方法
#$ret_sync = $user_client->getUser();
$i = 1;
while ($i < 1000) {
    $ret_sync = $user_client->getUser();
    $i++;
}
print_r($ret_sync);
Beispiel #3
0
 /**
  * 设置/获取服务端地址
  * @param array $address_array
  */
 public static function config($address_array = array())
 {
     if (!empty($address_array)) {
         self::$addressArray = $address_array;
     }
     return self::$addressArray;
 }
Beispiel #4
0
 public function rpcAction()
 {
     //rpc调用
     Yaf_Dispatcher::getInstance()->autoRender(FALSE);
     $sd = new RpcClient();
     $datas = array('name' => 'userinfo', 'result' => '{"id":3,"name"=>"zqf",email:"*****@*****.**"}');
     $sd->send($datas);
     $info = $sd->getresult();
     print_r($info);
     $sd->close();
     exit;
 }
Beispiel #5
0
 public function close()
 {
     $this->client->close();
 }
 public static function setSwooleClient()
 {
     self::$useSwoole = true;
 }
Beispiel #7
0
<?php

require_once '../../config/config.php';
require_once '../../lib/Thumper/RpcClient.php';
require_once '../../lib/php-amqplib/amqp.inc';
$client = new RpcClient(HOST, PORT, USER, PASS, VHOST);
$client->initClient();
$client->addRequest($argv[1], 'charcount', 'charcount');
//the third parameter is the request identifier
echo "Waiting for replies…\n";
$replies = $client->getReplies();
var_dump($replies);
Beispiel #8
0
<?php

/*测试,先编译php_safclient库,把它放到 `php-config --extension-dir`指向的目录中
 */
include "../../src/safclient.php";
$request_data = '{"person":[{"name":"xu","id":1,"email":"*****@*****.**"}]}';
/*
// 测试长连接速度,测试一个连接差不多可以达到1w每秒
$client = new RpcClient("127.0.0.1", 8000, true);
if ($client->init()){
  for ($i = 0; $i < 10000; $i++) {
    $response_data = $client->RawCallMethod("AddressBookService", "add", $request_data, 2);
    //echo $response_data;
  }
} else {
  echo "can't connect\n";
}
*/
// 测试短连接时客户端的速度,因为RpcClient要进行初始化和连接,在关闭时要进行资源和线
// 程释放,所以需要一定时间测试发现差不多1秒只能调用800次,所以对于大并发客户端,最好
// 不要用这种方式,不然就要保证有多个线程同时运行了;测试时注意最大
// fd的限制
for ($i = 0; $i < 1000; $i++) {
    $client = new RpcClient("127.0.0.1", 8000, true);
    if ($client->init()) {
        $response_data = $client->RawCallMethod("AddressBookService", "add", $request_data, 2);
        // echo $response_data;
    } else {
        echo "can't connect\n";
    }
}
Beispiel #9
0
<?php

include 'RpcClient.php';
//配置服务端列表
$address_array = array('127.0.0.1:6666', '127.0.0.1:6666');
RpcClient::config($address_array);
//检测是否装了swoole扩展有则用swoole_client方式,没有则用socket方式
if (extension_loaded('swoole')) {
    RpcClient::setSwooleClient();
}
// User对应/Jsonrpc/Services/User.php 中的User类
$user_client = RpcClient::instance('User');
// getInfoByUid对应User类中的getInfoByUid方法
$uid = 567;
$ret_sync = $user_client->getInfoByUid($uid);
var_dump($ret_sync);
//通过rpc操作redis的例子
$redis_client = RpcClient::instance('MyRedis');
$set_res = $redis_client->set('jsonrpc', 'hello json rpc654', 30);
var_dump($set_res);
$get_res = $redis_client->get('jsonrpc');
var_dump($get_res);
//调用不存在的函数
$list_res = $redis_client->list('jsonrpc');
var_dump($list_res);
Beispiel #10
0
 public function setClassName($className)
 {
     return RpcClient::instance($className);
 }