Exemple #1
0
        $_SERVER['QUERY_STRING'] = $parts['query'];
        parse_str($_SERVER['QUERY_STRING'], $_GET);
        $headers = evhttp_request_headers($r);
        // normalize to php way
        foreach ($headers as $name => $value) {
            $_SERVER["HTTP_" . str_replace("-", "_", strtoupper($name))] = $value;
        }
        echo "script-land memory: " . memory_get_usage() . "\n";
    }
    public function processRequest($r)
    {
        try {
            $this->_initRequest($r);
            $response = $this->controller->dispatch();
        } catch (Exception $e) {
            return $e->__toString();
        }
        return evhttp_response_set($response->getBody(), $response->getHttpResponseCode(), "OK");
    }
    public function run()
    {
        event_init();
        $this->httpd = evhttp_start($this->addr, $this->port);
        evhttp_set_gencb($this->httpd, array($this, 'processRequest'));
        echo "Application listening at {$this->addr}:{$this->port}...\n";
        event_dispatch();
    }
}
$app = new AppServer("0.0.0.0", 8080);
$app->run();