Source

trivial-remote-objects / php / server.php

<?
/*
 * JSON RPC Framework Server Side code 
 * 
 * calling rpcServer($functions); handles one RPC request per HTTP request. 
 *
 * Usage: 
 * rpcServer(array("someRPCFunctionDefinedInThisFile"=>False,
 *                 "someAnonFunc"=>function{ ... }, //requires PHP>=5.3.0
 *                 "someRPCFunction"=>"some/file/defining-or-requred-by/the/RPCFunc.php", 
 *                   ...));
 *
 * functions should return normal PHP values - strings/numbers/arrays/objects-and-assocs
 * the RPC code serializes them and deserializes them as Javascript equivalents 
 * (strings/numbers/arrays/objects respectively,
 *  note only public members of objects will be sent to the client)
 * it is important NOT to echo anything in an RPC func, it will break the RPC protocol format!
 *
 * Request Format:
 * POST application/x-www-form-urlencoded variables:
 *  'f' - the name of the function to be called
 *  'a' - a JSON encoded array of arguments
 *
 * Response Format:
 * {error:"Error Message As JSON Encoded String"}
 * or
 * {success:{some:"JSON", encoded:["object"]}
 *
 */
include_once "autoload.php";

function rpcServer($rpcs){
  RPCFunctions::serveRPC($rpcs);
}