2011-09-12 23:53:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2011-09-13 00:47:56 +00:00
|
|
|
* Example standalone HTTP server that routes all .php URIs to PHP files under ./www,
|
|
|
|
* and routes all other URIs to static files under ./www.
|
2011-09-12 23:53:38 +00:00
|
|
|
*
|
|
|
|
* index.php is used as the directory index.
|
|
|
|
*
|
2011-09-13 00:47:56 +00:00
|
|
|
* Just run it on the command line like "php server.php".
|
2011-09-12 23:53:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
require_once __DIR__ . '/httpserver/httpserver.php';
|
|
|
|
|
|
|
|
class ExampleServer extends HTTPServer
|
|
|
|
{
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct(array(
|
|
|
|
'port' => 8002,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
function route_request($request)
|
|
|
|
{
|
|
|
|
$uri = $request->uri;
|
|
|
|
|
|
|
|
$doc_root = __DIR__ . '/www';
|
|
|
|
|
|
|
|
if (preg_match('#/$#', $uri))
|
|
|
|
{
|
|
|
|
$uri .= "index.php";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (preg_match('#\.php$#', $uri))
|
|
|
|
{
|
|
|
|
return $this->get_php_response($request, "$doc_root$uri");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $this->get_static_response($request, "$doc_root$uri");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$server = new ExampleServer();
|
|
|
|
$server->run_forever();
|