예제 #1
0
function test_callback($evhttp_request)
{
    echo "script-land memory: " . memory_get_usage() . " and real memory from system: " . memory_get_usage(true) . "\n";
    $uri = evhttp_request_uri($evhttp_request);
    $ct = evhttp_request_find_header($evhttp_request, 'Content-Type');
    echo "URI: {$uri}\n";
    echo "Content-Type: {$ct}\n";
    print_r(evhttp_request_headers($evhttp_request));
    echo evhttp_request_body($evhttp_request);
    evhttp_response_add_header($evhttp_request, "Content-Type", "text/plain");
    return evhttp_response_set("Hello World!", 200, "OK");
}
예제 #2
0
파일: main.php 프로젝트: dreamsxin/Kellner
 public function processRequest($r)
 {
     try {
         printf("Used script-land memory %.2f MB\n", memory_get_usage() / (1024 * 1024));
         $uri = evhttp_request_get_uri($r);
         $parts = parse_url($uri);
         // let's process the request with the chosen webservice protocol
         switch (trim($parts['path'], "/")) {
             case "xmlrpc":
                 // set custom request, since we have to get post data through another function
                 $request = new EvHttp_XmlRpc_Request($r);
                 $this->xmlrpc_server->setRequest($request);
                 $response = $this->xmlrpc_server->handle();
                 unset($request);
                 evhttp_response_add_header($r, "Content-Type", "text/xml");
                 return evhttp_response_set($response->__toString(), 200, "OK");
             case "jsonrpc":
                 if ("GET" == evhttp_request_method($r)) {
                     // Grab the SMD
                     $smd = $this->jsonrpc_server->getServiceMap();
                     // Return the SMD to the client
                     evhttp_response_add_header($r, "Content-Type", "application/json");
                     return evhttp_response_set($smd, 200, "OK");
                 } else {
                     // set custom request, since we have to get post data through another function
                     $request = new EvHttp_Json_Request($r);
                     $this->jsonrpc_server->setResponse(new Zend_Json_Server_Response());
                     $response = $this->jsonrpc_server->handle($request);
                     unset($request);
                     evhttp_response_add_header($r, "Content-Type", "application/json");
                     return evhttp_response_set($response->toJson(), 200, "OK");
                 }
             default:
                 return evhttp_response_set("Invalid Protocol", 500, "Error");
         }
     } catch (Exception $e) {
         return $e->__toString();
     }
 }