Exemplo n.º 1
0
<?php

require_once '../src/Hprose.php';
function hello($name)
{
    echo "Hello {$name}!";
    return "Hello {$name}!";
}
function e()
{
    throw new Exception("I am Exception");
}
function ee()
{
    require "andot";
}
function asyncHello($name, $callback)
{
    sleep(3);
    $callback("Hello async {$name}!");
}
$server = new HproseHttpServer();
$server->setErrorTypes(E_ALL);
$server->setDebugEnabled();
$server->addFunction('hello');
$server->addFunctions(array('e', 'ee'));
$server->addAsyncFunction('asyncHello');
$server->addFilter(new HproseJSONRPCServiceFilter());
$server->start();
<?php

require_once 'hprose-php/src/Hprose.php';
require_once 'hprose-filter-init.php';
function onBeforeInvoke($name, &$args, $byref, $context)
{
    foreach ($args as $k => $arg) {
        $args[$k] = decrypt($arg);
    }
}
function onAfterInvoke($name, &$args, $byref, &$result, $context)
{
    $result = encrypt($result);
}
function testFilter($name)
{
    return 'Args: ' . $name;
}
$server = new HproseHttpServer();
$server->addFilter(new serverFilter());
// 只加密参数启用
// $server->onBeforeInvoke = 'onBeforeInvoke';
// $server->onAfterInvoke  = 'onAfterInvoke';
$server->addFunction('testFilter');
$server->start();