forked from grugnog/httpserver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_server.php
More file actions
46 lines (38 loc) · 1.04 KB
/
example_server.php
File metadata and controls
46 lines (38 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
/*
* Example standalone HTTP server that routes all .php URIs to PHP files under ./example_www,
* and routes all other URIs to static files under ./example_www.
*
* index.php is used as the directory index.
*
* Just run it on the command line like "php example_server.php".
*/
require_once dirname(__DIR__) . '/httpserver.php';
class ExampleServer extends HTTPServer
{
function __construct()
{
parent::__construct(array(
'port' => 8002,
));
}
function route_request($request)
{
$uri = $request->uri;
$doc_root = __DIR__ . '/example_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();