Demonstrates reading specific byte ranges from a file instead of loading the entire content.
- Reading a subset of bytes with
read($from, $to) $fromis the starting byte position (inclusive)$tois the ending byte position (exclusive)- Calling
read()with no arguments reads the entire file - Throws
FileExceptionif the requested range exceeds the file size
- Resumable downloads
- Reading headers from large binary files
- Sampling content without loading everything into memory
File::read(int $from = -1, int $to = -1)— When both default to-1, reads the full file. Otherwise reads bytes from$fromup to$to.
php examples/partial-read.php