jsonrpc php使用,php-JsonRPC
发布日期:2021-06-24 13:10:37 浏览次数:3 分类:技术文章

本文共 1339 字,大约阅读时间需要 4 分钟。

软件简介

JsonRPC 2.0 Client and Server

轻量级 Json-RPC 2.0 客户端和服务端的php扩展,基于 multi_curl +

epoll的并发客户端,依据jsonrpc协议规范。

服务端:

$server = new Jsonrpc_Server();

// style one function variable

$add1 = function($a, $b){

return $a + $b;

};

$server->register('addition1', $add1);

// style two function string

function add2($a, $b){

return $a + $b;

}

$server->register('addition2', 'add2');

// style three function closure

$server->register('addition3', function ($a, $b) {

return $a + $b;

});

//style four class method string

class A

{

static public function add($a, $b)

{

return $a + $b;

}

}

$server->register('addition4', 'A::add');

echo $server->execute();

//output >>>

//{"jsonrpc":"2.0","id":null,"error":{"code":-32700,"message":"Parse error"}}

客户端:

$client = new Jsonrpc_Client(1);

$client->call('http://localhost/server.php', 'addition1', array(3,5));

$client->call('http://localhost/server.php', 'addition2', array(10,20));

$client->call('http://localhost/server.php', 'addition3', array(2,8));

$client->call('http://localhost/server.php', 'addition4', array(6,15));

/* ... */

$result = $client->execute();

var_dump($result);

//output >>>

/*

array(2) {

[0]=>

array(3) {

["jsonrpc"]=>

string(3) "2.0"

["id"]=>

int(110507766)

["result"]=>

int(8)

}

[1]=>

array(3) {

["jsonrpc"]=>

string(3) "2.0"

["id"]=>

int(1559316299)

["result"]=>

int(30)

}

...

}

*/

转载地址:https://blog.csdn.net/weixin_33001305/article/details/115237771 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:imagemagick+php版本,php版本 5.2.14 按照论坛里搜的imagemagick教程安装不成功
下一篇:php+7+php+5.6,CentOS 7 + PHP 5.6.12

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年04月24日 16时53分27秒