Q:

How do I disable PHP's file read/write buffers?

If I write a line to a file, then flush the buffer, then write a second line, then seek to the beginning and read the file -- it only reads the first line. It's like it doesn't think I've written the second line.
Code to reproduce:
$fh = fopen('filename.dat', 'r+');
stream_set_write_buffer($fh, 0);
stream_set_read_buffer($fh, 0);
fwrite($fh, "Testing 123.\n");
fflush($fh);
fwrite($fh, "Testing 456.\n");
fflush($fh);
fseek($fh, 0);
echo fgets($fh, 26);
fclose($fh);

That will output...
"Testing 123.\n" 

instead of 
"Testing 123.\nTesting 456.\n".

I'm using PHP 5.4.16.
Help! This is driving me mad!

A:

fgets() reads one line, i.e. if it encounters a linebreak/carriage-return character it stops reading. 
You might be interested in http://docs.php.net/fread

