status = $status; $this->meta = $meta; } public function getHeader() { return sprintf("%s %s\r\n", $this->status, $this->meta); } public function send($client) { $result = fwrite($client, $this->getHeader()); if (!$result) { return false; } if ($this->filepath) { $size = filesize($this->filepath); $fp = fopen($this->filepath, "rb"); if (false === $fp) { throw new \Exception("Error reading file '{$this->filepath}'"); } $result = 1; while (!feof($fp) && $result) { // If the client cancels, bail out before trying large files // So, result will be 0 if the client cancels (broken socket) $result = fwrite($client, fread($fp, 8192)); } fclose($fp); return $size; } else { $body = $this->getBody(); fwrite($client, $body); return mb_strlen($body); } } public function setBody($body = '') { $this->body = $body; return $this; } public function getBody() { if ($this->filepath) { $this->body = file_get_contents($this->filepath); } return $this->body; } public function setStaticFile($filepath) { $this->filepath = $filepath; return $this; } public function setStatus($status) { $this->status = $status; return $this; } public function setMeta($meta) { $this->meta = $meta; return $this; } }