<?php $http = new Event\HTTP(); $srv = $http->createServer(function ($req, $res) { $res->write("Hello World immediately\n"); setTimeout(function () use(&$res) { $res->end("Goodbye world 5 seconds later\n"); }, 5000); }); $srv->listen(8080, '127.0.0.1');
<?php /// Bascically the same as in the node.js manual, weird. $http = new Event\HTTP(); $srv = $http->createServer(function ($request, $response) { $response->writeHead(200, array('Content-Type' => 'text/plain')); $response->end("Hello World\n"); })->listen(8080); print "Server running at http://1270.0.1:8080\n";
<?php $http = new Event\HTTP(); $srv = $http->createServer(function ($req, $res) { if ($req->method == 'GET') { $url = $req->url; $res->end("THAT WAS A GET REQUEST FOR {$url}\n"); } else { if ($req->method == 'POST') { // can also do $req->on('file') for each file as they arrive // or $req->on('data') for each block as recieved. $req->on('end', function () use($req, $res) { $files = $req->uploadedFiles(); $res->writeHead(200, array('Content-Type' => 'application/derp')); foreach ($files as $file_info) { $res->write("Accepted file {$file_info['filename']}\n"); } $url = $req->url; $res->end("THAT WAS A POST REQUEST FOR {$url}\n"); }); } } }); $srv->listen(8080);