socket to browser
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 | |
error_reporting(E_ALL); | |
set_time_limit(0); | |
ob_implicit_flush(); | |
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); | |
if (socket_bind($sock, '127.0.0.10', 888) === false) { | |
die('cannot bind' . PHP_EOL); | |
} | |
if (socket_listen($sock, 5) === false) { | |
die('cannot listen' . PHP_EOL); | |
} | |
do { | |
if (($msgsock = socket_accept($sock)) === false) { | |
echo "socket_accept() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n"; | |
} | |
$msg = "HTTP/1.1 200\r\nContent-Type: text/html\r\n\r\n" | |
. "<!DOCTYPE html><html><head></head><body><h1>asd</h1></body></html>\r\n\r\n"; | |
// Request does NOT work when read is uncommented. | |
//$buf = socket_read($msgsock, 4012, PHP_NORMAL_READ); | |
//echo $buf . PHP_EOL; | |
socket_write($msgsock, $msg, strlen($msg)); | |
socket_close($msgsock); | |
continue; | |
} while (true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment