function threadmain() { // Read request block $buf = ""; while (true) { $rl = socket_read($this->sock, 4096, PHP_BINARY_READ); if (false == $rl) { socket_close($this->sock); return; } else { $buf = $buf . $rl; } if (strpos($buf, "\r\n\r\n")) { break; } else { console::writeLn('%s', $buf); } } $db = explode("\r\n\r\n", $buf); $data = $db[0]; // Put back the rest of the buffer for posts etc $buf = join('', array_slice($db, 1)); $request = new HttpRequest($data); // data $response = new HttpResponse(); // Pop the header off the buffer $status = call_user_func_array($this->handler, array(&$request, &$response)); if ($status == 0) { $status = 200; } $peer = ""; $port = 0; socket_getpeername($this->sock, $peer, $port); console::writeLn("%s %s:%d %d %s", $request->getMethod(), $peer, $port, $status, $request->getUri()); $response->writeHeaders($this->sock, 200); $response->writeContent($this->sock); socket_shutdown($this->sock, 2); usleep(50000); socket_close($this->sock); }