Cake\Network\Response::_sendFile PHP Method

_sendFile() protected method

Reads out a file, and echos the content to the client.
protected _sendFile ( Cake\Filesystem\File $file, array $range ) : boolean
$file Cake\Filesystem\File File object
$range array The range to read out of the file.
return boolean True is whole file is echoed successfully or false if client connection is lost in between
    protected function _sendFile($file, $range)
    {
        $compress = $this->outputCompressed();
        ob_implicit_flush(true);
        $file->open('rb');
        $end = $start = false;
        if ($range) {
            list($start, $end) = $range;
        }
        if ($start !== false) {
            $file->offset($start);
        }
        $bufferSize = 8192;
        set_time_limit(0);
        session_write_close();
        while (!feof($file->handle)) {
            if (!$this->_isActive()) {
                $file->close();
                return false;
            }
            $offset = $file->offset();
            if ($end && $offset >= $end) {
                break;
            }
            if ($end && $offset + $bufferSize >= $end) {
                $bufferSize = $end - $offset + 1;
            }
            echo fread($file->handle, $bufferSize);
        }
        $file->close();
        return true;
    }