【问题标题】:file_put_contents of file_get_contents('index.php') will write PHP codefile_get_contents('index.php') 的 file_put_contents 将编写 PHP 代码
【发布时间】:2013-08-11 09:33:47
【问题描述】:

我想每 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 代码(我对此感到非常不满.....)

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

谢谢

【问题讨论】:

  • 我认为其他帖子包含您的答案:stackoverflow.com/questions/851367/…
  • $path 更改为有效的http 资源。例如,如果您的站点位于localhost/website 下,则使用http://localhost/website/。这是针对 file_get_contents 部分的,file_put_contents 应该像 '/home/......../mypath/html

标签: php caching file-get-contents


【解决方案1】:
$homePage = file_get_contents($path.'index.php');

改成

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-24
    • 2014-09-14
    • 2014-02-13
    • 2013-02-15
    相关资源
    最近更新 更多