I'm trying to increase the response time of my site by creating a file cache.
Instead of having to recreate the .php page each time, my server will first look to see if it is already created and serve either the .html or .html.gz file depending on the user's browser. If the file does not exist then the .php page is loaded which also creates the two static files.
At the end of my php file I have the following code:
file_put_contents("/cache/".$name.".html", $file);
exec("gzip -9f /absolute/path/to/cache/".$name.".html");
file_put_contents("/cache/".$name.".html", $file);
On line 1 I create the file.
On line 2 I gzip this file to create the .html.gz version
On line 3 I recreate the file because line 2 has destroyed it.
I'd like to rewrite my code so line 2 doesn't destroy the original file, just saves a copy. That way I can eliminate step 3 which is a pure waste.
Is this possible?