0

I want to cache ever x minutes my homepage because it has many requests and the content doesn't change that often,

This is what I'm trying:

<?php
    ini_set('error_reporting', 1);
    error_reporting(E_ALL);
    $path = '/home/......../mypath/html/';
    if(true){
        $homePage = file_get_contents($path.'index.php');
        file_put_contents('indexx.html', $homePage);
        //echo $homePage;
    }   
?>

The problem is that instead of getting the html result code it returns the php code (i am pretty sourprised about this.....)

Any idea why? and how to get the rendered version instead?

thanks

Toni Michel Caubet
  • 19,333
  • 56
  • 202
  • 378
  • I think this other post contains your answer: http://stackoverflow.com/questions/851367/how-to-execute-and-get-content-of-a-php-file-in-a-variable – Watters Aug 11 '13 at 09:36
  • 1
    Change the `$path` to a valid http resource. For example, if you site is under `localhost/website` then use `http://localhost/website/`. This is for the file_get_contents part, file_put_contents should stay like `'/home/......../mypath/html` – HamZa Aug 11 '13 at 09:37

1 Answers1

2
$homePage = file_get_contents($path.'index.php');

change to

$homePage = file_get_contents('http://www.yourdomainname.com/index.php');
mccakici
  • 550
  • 3
  • 7