JSON-RPC client and server for PHP 5.3+
Based on tivoka in version 3.4.0
- JSON-RPC client/server library for PHP (supports v1.0 and v2.0 specs)
- Easily switch between the v1.0 and v2.0 specs
- HTTP, TCP and Websocket transports available
- New: CurlHTTP available, used if HTTP not allowed (allow_url_fopen)
These are just some quick examples. Check out the docs in /doc/
.
Do a request through HTTP...
<?php
$connection = BugBuster\Tivoka\Client::connect('http://example.com/api')
$request = $connection->sendRequest('substract', array(51, 9));
print $request->result;// 42
?>
...or plain TCP
<?php
$connection = BugBuster\Tivoka\Client::connect(array('host' => 'example.com', 'port' => 1234))
$request = $connection->sendRequest('substract', array(51, 9));
print $request->result;// 42
?>
...or WebSocket
<?php
$connection = BugBuster\Tivoka\Client::connect('ws://example.com/api')
$request = $connection->sendRequest('substract', array(51, 9));
print $request->result;// 42
?>
Create a server
<?php
$methods = array(
'substract' => function($params) {
list($num1, $num2) = $params
return $num1 - $num2;
}
);
BugBuster\Tivoka\Server::provide($methods)->dispatch();
?>
- Set up
composer.json
in your project directory:
{
"require":{"bugbuster/tivoka":"*"}
}
- Run composer:
$ php composer.phar install
Now, include 'vendor/autoload.php'
Copyright 2011-2012 by Marcel Klehr, MIT License.
Copyright (c) 2014-2016 Glen Langer (Contao Version), MIT License.