bugbuster / tivoka
通用的JSON-RPC客户端/服务器库。正确实现的JSON-RPC!Contao版本
1.1.1
2016-12-26 14:44 UTC
Requires
- php: >=5.3
- contao/core: >=3.3.1,<4
- textalk/websocket: 1.0.*
Replaces
- contao-legacy/tivoka: 1.1.1
This package is auto-updated.
Last update: 2024-09-23 09:59:51 UTC
README
JSON-RPC客户端和服务器(支持PHP 5.3+)
基于tivoka版本3.4.0
- PHP的JSON-RPC客户端/服务器库(支持v1.0和v2.0规范)
- 轻松在v1.0和v2.0规范之间切换
- 支持HTTP、TCP和Websocket传输
- 新功能:当HTTP不被允许时(允许_url_fopen),将使用CurlHTTP
示例
这些只是快速示例。请查看/doc/
中的文档。
通过HTTP进行请求...
<?php $connection = BugBuster\Tivoka\Client::connect('http://example.com/api') $request = $connection->sendRequest('substract', array(51, 9)); print $request->result;// 42 ?>
...或者纯TCP
<?php $connection = BugBuster\Tivoka\Client::connect(array('host' => 'example.com', 'port' => 1234)) $request = $connection->sendRequest('substract', array(51, 9)); print $request->result;// 42 ?>
...或者WebSocket
<?php $connection = BugBuster\Tivoka\Client::connect('ws://example.com/api') $request = $connection->sendRequest('substract', array(51, 9)); print $request->result;// 42 ?>
创建服务器
<?php $methods = array( 'substract' => function($params) { list($num1, $num2) = $params return $num1 - $num2; } ); BugBuster\Tivoka\Server::provide($methods)->dispatch(); ?>
安装
安装composer包
- 在您的项目目录中设置
composer.json
{
"require":{"bugbuster/tivoka":"*"}
}
- 运行composer
$ php composer.phar install
现在,包含include 'vendor/autoload.php'
许可
版权所有2011-2012年Marcel Klehr,MIT许可。
版权所有(c) 2014-2016 Glen Langer(Contao版本),MIT许可。