Handling large files with(out) PHP

As one man was quoted "640K of memory should
be enough for anybody" no one will need to access more than 2 GB data. What happens if you – just for scientific reasons of course – try to access larger files using your 32bit hardware and your favorite programming language PHP? For a first test let’s take this file

$ ls -hl dummyfile
-rw-r--r-- 1 johannes users 2.2G 2006-02-02 14:32 dummyfile

and a bit code, to read the first few bytes of it

$fp = fopen("dummyfile", "r");
$data = fread($fp, 255);


Now, time to run the script, but first let’s think what the right behavior is. In this case it’s quite simple, we just expect an empty page. So let’s see:

Warning: fopen(dummyfile): failed to open stream: File too large in ....