forked from white-poto/zebra_http_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Zebra_Server.php
36 lines (29 loc) · 994 Bytes
/
Zebra_Server.php
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
<?php
define('ZEBRA_ROOT', dirname(__FILE__));
require './core/Mpass/Server.php';
require './core/include/HandleFactory.class.php';
require './core/Exception/ZebraException.include.php';
class ZebraPserver implements Mpass_IExecutor {
function execute(Mpass_Request $client) {
try{
$header = '';
$header = $client->read(1024);
$request = new RequestModel($header);
$handle = HandleFactory::getResponseHandle($request->isStatic());
$response = $handle->handle($header);
$client->write($response);
Mpass_Log::record($header, __METHOD__);
return true;
}catch (Exception $e){
$EResponse = 'HTTP/1.0 '.$e->getCode().' '.$e->getMessage().chr(13).chr(10);
$EResponse .= 'Date:'.date("D, d M Y G:i:s \G\M\T").chr(13).chr(10).chr(13).chr(10);
$client->write($EResponse);
Mpass_Log::record($EResponse, __METHOD__);
return true;
}
}
}
$host = "127.0.0.1";
$port = 8080;
$service = new Mpass_Server($host, $port, new ZebraPserver);
$service->run();