added tips to lamer.bash help
[mirrors/Programs.git] / php / skripty / http_serv.php
1 <?php
2
3 // set some variables
4 $host = "localhost";
5 $port = 81;
6
7 $header =
8 "HTTP/1.0 200 OK\n".
9 "Server: Harvie's HTTPd\n".
10 "Connection: close\n\n";
11
12 /*
13 HTTP/1.0 200 OK
14 Date: Thu, 05 Jul 2007 17:28:16 GMT
15 Server: Apache/2.0.59 (Win32) PHP/5.1.4
16 Content-Length: 5568
17 Connection: close
18 Content-Type: text/html;charset=utf-8
19 */
20
21 // don't timeout!
22 set_time_limit(0);
23
24 while(1) {
25
26 $socket = socket_create(AF_INET, SOCK_STREAM, 0) or die("Could not create socket\n");
27 $result = socket_bind($socket, $host, $port) or die("Could not bind to socket\n");
28 $result = socket_listen($socket, 3) or die("Could not set up socket listener\n");
29
30 // accept incoming connections
31 // spawn another socket to handle communication
32 $spawn = socket_accept($socket) or die("Could not accept incoming connection\n");
33
34 $loop = 1;
35 while($line = socket_read($spawn, 1024) && $loop) {
36 echo($line);
37 if(eregi("(GET|POST)", $line)) {
38 $line = trim($line);
39 echo($line);
40 $line = explode(" ", $line);
41 readfile(".".$line[1]);
42 $loop = 0;
43 }
44 }
45
46 // read client input
47 //$input = socket_read($spawn, 1024) or die("Could not read input\n");
48 // clean up input string
49 //$input = trim($input);
50 // reverse client input and send back
51 //$output = strrev($input) . "\n";
52 //socket_write($spawn, $output, strlen ($output)) or die("Could not write output\n");
53
54 // close sockets
55 socket_close($spawn);
56 socket_close($socket);
57
58 }
59
60 ?>
61
This page took 1.837893 seconds and 4 git commands to generate.