PHP文件编写问题

I'm trying to write to a file in PHP to cache the output of a small portion of code.

        ob_start();
        echo "Hello";
     $fp = fopen("cache/ttcache.php", 'w');
        fwrite($fp, ob_get_contents());
        fclose($fp);
        ob_end_flush();

The file exists and is blank. The fwrite function points to the correct location. It just doesn't write.

Any help?

Try to write first small word or sentence first.

fwrite($fp, 'hello')

Also check your file permission's should be writable.

Make sure ob_get_contents() is really not empty. Then try

fflush($fp);

right before fclose().