lib/blobfolio/common/file.php
public static function readfile_chunked(string $file, bool $retbytes=true) {
		if (! $file || ! @\is_file($file)) {
			return false;
		}

		$buffer = '';
		$cnt = 0;
		$chunk_size = 1024 * 1024;

		if (false === ($handle = @\fopen($file, 'rb'))) {
			return false;
		}

		while (! @\feof($handle)) {
			$buffer = @\fread($handle, $chunk_size);
			echo $buffer;
			\ob_flush();
			\flush();
			if ($retbytes) {
				$cnt += \strlen($buffer);
			}
		}

		$status = @\fclose($handle);

		// Return number of bytes delivered like readfile() does.
		if ($retbytes && $status) {
			return $cnt;
		}

		return $status;
	}
public static function readfile_chunked(string $file, bool $retbytes=true) {
		if (! $file || ! @\is_file($file)) {
			return false;
		}

		$buffer = '';
		$cnt = 0;
		$chunk_size = 1024 * 1024;

		if (false === ($handle = @\fopen($file, 'rb'))) {
			return false;
		}

		while (! @\feof($handle)) {
			$buffer = @\fread($handle, $chunk_size);
			echo $buffer;
			\ob_flush();
			\flush();
			if ($retbytes) {
				$cnt += \strlen($buffer);
			}
		}

		$status = @\fclose($handle);

		// Return number of bytes delivered like readfile() does.
		if ($retbytes && $status) {
			return $cnt;
		}

		return $status;
	}
public static function readfile_chunked ( string $ file , bool $ retbytes = true ) { if ( ! $ file || ! @ \ is_file ( $ file ) ) { return false ; } $ buffer = '' ; $ cnt = 0 ; $ chunk_size = 1024 * 1024 ; if ( false === ( $ handle = @ \ fopen ( $ file , 'rb' ) ) ) { return false ; } while ( ! @ \ feof ( $ handle ) ) { $ buffer = @ \ fread ( $ handle , $ chunk_size ) ; echo $ buffer ; \ ob_flush ( ) ; \ flush ( ) ; if ( $ retbytes ) { $ cnt += \ strlen ( $ buffer ) ; } } $ status = @ \ fclose ( $ handle ) ; // Return number of bytes delivered like readfile() does. if ( $ retbytes && $ status ) { return $ cnt ; } return $ status ; }
Read File in Chunks

This greatly reduces overhead if serving files through a PHP
gateway script.

@param string $file Path.
@param bool $retbytes Return bytes served like `readfile()`.
@return mixed Bytes served or status.
Read File in Chunks