Exemple #1
0
 public function serverAction()
 {
     $server = new Jsonrpc_Server();
     $server->register('find', function ($keywords, $offset = 0, $limit = 12) {
         $segmenter = new Search_Segment();
         $matcher = new Search_Match('gamedb');
         $text = $segmenter->cutString('lol');
         $data = $matcher->call($text, 0, 12);
         foreach ($data['list'] as $k => $v) {
             $configer = new Search_Config($v->app);
             $data['list'][$k] = array('title' => $configer->formatTitle($v->table, $v, $text), 'detail' => $configer->formatDetail($v->table, $v, $text), 'url' => $configer->formatUrl($v->table, $v), 'image_url' => $configer->formatImage($v->table, $v));
         }
         $data['keyword'] = $text;
         return $data;
     });
     echo $server->execute();
 }
<?php

$http = new swoole_http_server("127.0.0.1", 9501);
function add($a, $b)
{
    return $a + $b;
}
$http->on('Request', function ($request, $response) {
    if ($request->server['request_uri'] == "/jsonrpc_server") {
        $payload = $request->rawContent();
        $jsr_server = new Jsonrpc_Server($payload);
        $jsr_server->register('addition', 'add');
        $res = $jsr_server->execute();
        //var_dump($res);
        $response->end($res);
        unset($payload);
        unset($jsr_server);
        unset($res);
    } else {
        //var_dump($request);
        $response->end("error");
    }
});
$http->start();