'Writing to file with fwrite appears successful, but no file appears

All I am attempting to do is append to a file, and then read the file. In this case, I am appending 'hi', so my results look like 'hi', 'hihi', 'hihihi', etc. This works. What is so baffling is that if I then look at my temp dir, I see no file /tmp/bb.txt. How am I able to append to a file I cannot find in my file system? Am I under some sort of fake root or something?

$content is becoming a longer string each time, so it must be saving somewhere. When I step through, $x is true.

    public function testFileAction()
{

    $file = '/tmp/bb.txt';
    $x = file_exists($file);
    $mf = fopen($file, 'a');
    fwrite($mf, 'hi');
    fclose($mf);
    $mfr = fopen($file, 'r');
    $content = fread($mfr, filesize($file));
    fclose($mfr);
    echo $content;
}


Solution 1:[1]

Code is correct.

How are you running this? File can be owned by user used by server (apache for example). You (user in the terminal) probably don't have permission to read the file. Try sudo ls /tmp.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 matek997