PHP file_get_contents fails silently on files greater than 2Gb

Trying to run a script with file_get_contents on a file > 2Gb kept on failing silently
To fix this, I had to recompile my PHP with “D_FILE_OFFSET_BITS=64”
CFLAGS="-D_FILE_OFFSET_BITS=64" ./configure

No external libraries are needed to build this extension, but if you want PHP to support LFS (large files) on Linux, then you need to have a recent glibc and you need compile PHP with the following compiler flags: -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64.

Leave a Reply

Your email address will not be published.