Last active
September 22, 2019 14:26
-
-
Save lotfio/45dc7383811b2880fd041cd162fa1318 to your computer and use it in GitHub Desktop.
Create a usless PHP socket Server
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
#!/usr/bin/env php | |
<?php | |
$sock = socket_create(AF_INET, SOCK_STREAM, 0); | |
$bind = socket_bind($sock, "127.0.0.1", "9000"); | |
$listen = socket_listen($sock); | |
echo "\n starting server 127.0.0.1:9000\n\n"; | |
do | |
{ | |
$client = socket_accept($sock); | |
$request = socket_read($client, 1024); | |
$res = explode("\r\n", $request); | |
$uri = explode(" ", $res[0]); | |
$inp = "[".date("Y-m-d H:i:s")."][200] " . $uri[0] . " " . $uri[1] . "\n"; | |
fwrite(STDOUT, $inp); | |
$out = "HTTP/1.1 200 ok\r\n"; | |
$out .= "Date: 32132132 \r\n"; | |
$out .= "Server: lotfio \r\n"; | |
$out .= "\r\n"; | |
$out .= "Hello from Your server"; | |
/* | |
$o = file_get_contents("index.php"); | |
ob_start(); | |
eval("?>" . $o); | |
$out .= ob_get_clean(); | |
*/ | |
socket_write($client, $out, strlen($out)); | |
socket_close($client); | |
}while(true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment