file_get_contents('index.php')的file_put_contents将编写PHP代码

时间:2013-08-11 09:33:48

标签: php caching file-get-contents

我想在我的主页上永久缓存x分钟,因为它有很多请求,内容不会经常更改,

这就是我正在尝试的:

<?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;
    }   
?>

问题是,不是获取html结果代码而是返回php代码(我对此非常惊讶......)

知道为什么吗?以及如何获得渲染版本?

感谢

1 个答案:

答案 0 :(得分:2)

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

更改为

$homePage = file_get_contents('http://www.yourdomainname.com/index.php');