I wrote a program to generate large .SQL files for quickly populating very large databases. I scripted it in PHP. When I started coding I was using fopen()
You can write more than 2GB of data in a stream, not in a file (as the fseek internal pointer of the file is exceeding PHP limits, and streams are not usually seekable)
$target = fopen('test.tar', 'w'); //this is a file, limited by php to 2GB
$body = str_repeat("===", 1024 * 1024);
while(true)
fwrite($target, $test);
$target = popen('cat > test.tar', 'w'); //this is a stream, no limitation here
$body = str_repeat("===", 1024 * 1024);
while(true)
fwrite($target, $test);