Något i stil med detta (som väl liknar ditt alternativ 3) skulle jag nog gjort:
PHP-kod:
<?php
//Save
$object = array('text' => 'HTML content', 'title' => $title);
file_put_contents('cachefile', serialize($object));
?>
PHP-kod:
<?php
//Load
$object = unserialize(file_get_contents('cachefile'));
?>
Detta kräver dock lite RAM och du verkar ju vilja trycka ut datat direkt utan mellanlagring av hela filen i minnet (notera att din kod INTE uppfyller det kravet för närvarande). En högpresterande lösning vore då ditt alternativ 2, gärna kombinerat med en minnescache (memcached eller spara filerna på en RAM-disk). Men slopa include för då måste cachefilerna köras genom PHP-tolken trots att de bara innehåller ren HTML-kod. Använd readfile istället.
En optimering som gör att du slipper öppna två filer (varje filöppning tar såklart prestanda och i värsta fall disksökning till skilda delar av hårddisken) kan vara att utveckla ett eget filformat för alternativ 3. Lägg till exempel titlen på första raden och resten av filen sedan. Exempel:
PHP-kod:
<?php
//Save
$save = $title ."\n". $content;
file_put_contents('cachefile', $save);
?>
PHP-kod:
<?php
//Load
$fp = fopen('cachefile', 'r');
/*
Where you need the title, output first line.
Do not close the file pointer!
*/
echo fgets($fp);
/*
Where you later want the content, just fpassthru the rest of the file.
This will pass the content directly to the output buffer (and with output buffering disabled, directly to the network).
*/
fpassthru($fp);
?>