FilesystemFilesystem report7 repeated rounds

Whole-file reads vs 64 KiB streaming reads

A local filesystem comparison of file_get_contents and an explicit chunked fread loop on a 2 MiB fixture.

Filesystem scenario

What the application is trying to do

For a modest local file, how do whole-file and chunked-read approaches compare on this host?

Choosing a file API is partly a resource-boundary decision. A fast whole-file read can still be the wrong design for unbounded uploads or multi-gigabyte exports.

Filesystem cache state can dominate small local tests, so multiple rounds and limitations are essential.

Observed host behavior

Lowest measured median64 KiB chunked fread
Median time206.07 µs
Median spread239.89%

What this run shows: 64 KiB chunked fread completed this local read fixture sooner; peak memory, stream processing and file size determine whether whole-file loading is acceptable. The slowest-to-fastest median spread was 239.89% on the measured host.

Measured results. Lower median time is faster.
VariantMedianMiddle 50%Operations/sAdditional measure
64 KiB chunked freadFastest206.07 µs203.63 µs–209.56 µs4,8532,097,152 input bytes
file_get_contents700.40 µs666.88 µs–733.86 µs1,4282,097,152 input bytes

What changes outside the fixture

Read speed for a cached 2 MiB file says little about safe memory use on a 2 GiB file. Use this result as a local baseline for modest artifacts only.

Chunking is often selected to cap memory or process data incrementally. Whole-file reads are convenient when an enforced size limit makes allocation safe.

Read path and controls

Expected behavior

Whole-file reads may be efficient for modest files, while chunked reads provide bounded-memory behavior that matters more as files grow.

  1. Both variants read the same 2 MiB local fixture and count all returned bytes.
  2. The streaming path uses 64 KiB chunks and closes the handle each operation.
  3. The test does not flush the operating-system page cache between samples.
18operations/sample
7measured rounds
2variants
Medianprimary statistic
Open measured environment
Measurement run
2026-07-22T15:23:56+00:00
PHP
8.4.23 (cli)
Operating system
Linux 4.18.0-553.85.1.el8_10.x86_64
Architecture
x86_64
Processor
AMD EPYC-Rome Processor
Reported host memory
15.02 GiB host total
CLI OPcache
0
PHP memory limit
1024M
Loaded study extensions
json, openssl, zlib, mbstring, pdo_sqlite
Timing clock
hrtime(true)
Measured rounds
7

Before changing a production path

  • Enforce a maximum file size before using whole-file reads on external input.
  • Use streaming when files are large, unbounded or can be processed incrementally.
  • Benchmark storage-backed workloads with representative cache state and concurrency.

Storage variables not simulated here

  • Operating-system page cache is not cleared.
  • Remote storage, network filesystems and concurrent readers are not represented.

Primary documentation

These references document the PHP filesystem and hashing operations. Local storage behavior remains specific to the measured host.

Rerun against your storage layer