Login   Register  
PHP Classes
elePHPant
Icontem

File: examples/client.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Mark Rolich  >  JSON RPC Client and Server  >  examples/client.php  >  Download  
File: examples/client.php
Role: Example script
Content type: text/plain
Description: Example client
Class: JSON RPC Client and Server
Implements JSON RPC protocol client and server
Author: By
Last change:
Date: 2 years ago
Size: 1,434 bytes
 

Contents

Class file image Download
<?php
include '../JsonRpcClient.php';

$url 'http://' $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$serverUrl substr($url0strpos($url'client.php')) . 'server.php';

$client = new JsonRpcClient($serverUrl);

try {
    
// Call in context of server

    
$params = new StdClass();
    
$params->minuend 42;
    
$params->subtrahend 23;

    
$response $client->subtract($params1);
    
var_dump($response);

    
$params = array('subtrahend' => 42'minuend' => 23);

    
$response $client->subtract($params2);
    
var_dump($response);

    
// Simple call

    
$response $client->call('subtract', array(4223), 3);
    
var_dump($response);

    
$response $client->call('subtract', array('subtrahend' => 23'minuend' => 42), 4);
    
var_dump($response);

    
// Raw call
    
$response $client->rawcall('{"jsonrpc":"2.0","method":"subtract","params":{"subtrahend":23,"minuend":42},"id":5}');
    
var_dump($response);

    
// Batch call
    
$requests = array();
    
    
$requests[] = $client->prepare('subtract'21);
    
$requests[] = $client->prepare('subtract', array(2352), 2);
    
$requests[] = $client->prepare('subtract', array(4552), 3);
    
$requests[] = $client->prepare('subtract', array(752), 4);
    
$requests[] = $client->prepare('foobar', array(752), 5);

    
$response $client->callBatch($requests);
    
var_dump($response);
} catch (
Exception $e) {
    echo 
$e->getMessage();
}
?>