forked from ClanCatsStation/PHPWebserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver
39 lines (32 loc) · 965 Bytes
/
server
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
#!/usr/bin/env php
<?php
/*
*---------------------------------------------------------------
* Pure php webserver
*---------------------------------------------------------------
*
* This is the source code for the tutorial:
*/
use ClanCats\Station\PHPServer\Server;
use ClanCats\Station\PHPServer\Request;
use ClanCats\Station\PHPServer\Response;
require 'vendor/autoload.php';
// we never need the first argument
array_shift( $argv );
// the next argument should be the port if not use 80
if ( empty( $argv ) )
{
$port = 80;
} else {
$port = array_shift( $argv );
}
// create a new server instance
$server = new Server( '127.0.0.1', $port );
// start listening
$server->listen( function( Request $request )
{
// print information that we recived the request
echo $request->method() . ' ' . $request->uri() . "\n";
// return a response containing the request information
return new Response( '<pre>'.print_r( $request, true ).'</pre>' );
});