Something went wrong. Try again.
Instant MicroVMs/Unikernels for macOS and Linux
linux unikernel unikraft osv freebsd netbsd microvm libkrun
Something went wrong. Try again.
1.3 kB · 45 lines
PHP
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546#!/usr/local/bin/php -q<?phperror_reporting(E_ALL);
/* Allow the script to hang around waiting for connections. */set_time_limit(0);
/* Turn on implicit output flushing so we see what we're getting * as it comes in. */ob_implicit_flush();
$address = '0.0.0.0';$port = 8080;
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) === false) { echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";}
if (socket_bind($sock, $address, $port) === false) { echo "socket_bind() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";}
if (socket_listen($sock, 5) === false) { echo "socket_listen() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n";}
do { if (($msgsock = socket_accept($sock)) === false) { echo "socket_accept() failed: reason: " . socket_strerror(socket_last_error($sock)) . "\n"; break; } /* Send instructions. */ $msg = "HTTP/1.1 200 OK\r\n" . "Content-Type: text/html\r\n" . "Content-Length: 14\r\n" . "Connection: close\r\n" . "\r\n" . "Hello, World!\n"; socket_write($msgsock, $msg, strlen($msg));
socket_close($msgsock);} while (true);
socket_close($sock);?>