Created
June 7, 2017 15:55
-
-
Save hanhan1978/a6d86f4ce45a0da787ed7be4f1c6337f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$sock = @socket_create_listen(8080); | |
if(!$sock){die("port in use\n");} | |
$client_sock = socket_accept($sock); | |
while(true){ | |
$buf = socket_read($client_sock, 1024); | |
if(preg_match('/GET ([^ ]+)/', $buf, $m) && is_file('./htdocs/'.$m[1])){ | |
$content = file_get_contents('./htdocs/'.$m[1]); | |
$res = "HTTP/1.1 200 OK\nContent-Type: text/html\nCache-Control: max-age=8640000\nAccept-Ranges: bytes\nContent-Length: 197\nServer: HTTPServer/0.1\n\n"; | |
socket_write($client_sock, $res.$content); | |
} | |
socket_close($client_sock); | |
$client_sock = socket_accept($sock); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment