public function sendfile($path, $cb, $pri = EIO_PRI_DEFAULT) { $req = $this; try { $this->header('Content-Type: ' . MIME::get($path)); } catch (RequestHeadersAlreadySent $e) { } if ($this->conn->sendfileCap) { $req->ensureSentHeaders(); $req->conn->onWriteOnce(function ($conn) use($req, $path, $cb, $pri) { FS::sendfile($req->conn->fd, $path, $cb, 0, null, $pri); }); return; } $first = true; FS::readfileChunked($path, $cb, function ($file, $chunk) use($req, &$first) { // readed chunk if ($first) { try { $req->header('Content-Length: ' . $file->stat['st_size']); } catch (RequestHeadersAlreadySent $e) { } $first = false; } $req->out($chunk); }); }