All*_*nde 12 php caching output-buffering
所以,我正在寻找比这更有效的东西:
<?php
ob_start();
include 'test.php';
$content = ob_get_contents();
file_put_contents('test.html', $content);
echo $content;
?>
Run Code Online (Sandbox Code Playgroud)
以上问题:
有什么建议?
有趣的问题; 不要以为我以前试过解决这个问题.
我想你需要从你面向前面的PHP脚本到你的服务器有第二个请求.这可以是对http://localhost/test.php的简单调用.如果使用fopen-wrappers,则可以使用fread()在呈现时拉取test.php的输出,并在收到每个块后,将其输出到屏幕并将其附加到test.html文件.
这是可能的样子(未经测试!):
<?php
$remote_fp = fopen("http://localhost/test.php", "r");
$local_fp = fopen("test.html", "w");
while ($buf = fread($remote_fp, 1024)) {
echo $buf;
fwrite($local_fp, $buf);
}
fclose($remote_fp);
fclose($local_fp);
?>
Run Code Online (Sandbox Code Playgroud)