Created
April 3, 2011 19:15
-
-
Save becojo/900688 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 | |
set_time_limit (0); | |
$address = '127.0.0.1'; | |
$port = intval($argv[1]); // php server.php 3000 | |
$sock = socket_create(AF_INET, SOCK_STREAM, 0); | |
try { | |
socket_bind($sock, $address, $port); | |
} catch(Execption $e){ | |
exit(0); // Socket bind failed. Often because the port is used. | |
} | |
socket_listen($sock); | |
while($client = socket_accept($sock)){ | |
$input = socket_read($client, 1024); | |
echo $input; // Output the request | |
socket_write($client, "HTTP/1.1 200 OK\n\r"); | |
socket_write($client, 'Date: '.date('r')."\n\r"); | |
socket_write($client, "Connection: close"); | |
socket_write($client, "Content-Type: text/html;charset=utf-8\n\r"); | |
socket_write($client, "\n\r"); | |
socket_write($client, "Hello"); | |
socket_close($client); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment