bugbuster/tivoka

The universal JSON-RPC client/server library. JSON-RPC done right! Contao version

1.1.1 2016-12-26 14:44 UTC

This package is auto-updated.

Last update: 2024-11-23 10:25:29 UTC


README

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)

Examples

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();
?>

Installation

Install composer package

  1. Set up composer.json in your project directory:
{
  "require":{"bugbuster/tivoka":"*"}
}
  1. Run composer:
$ php composer.phar install

Now, include 'vendor/autoload.php'

License

Copyright 2011-2012 by Marcel Klehr, MIT License.

Copyright (c) 2014-2016 Glen Langer (Contao Version), MIT License.