dongtazu3080 2014-12-14 14:36 采纳率: 100%
浏览 45

如何缓存php页面

Hello i have a problem with my website. It is running slow. I asked the my server provider why is that, and they replied its because the webiste uses many embedded urls like youtube, vimeo, dailymotion and so on. And so i have to cache these embedded urls. Anyone knows how to do that? I viewed this online. So all i have to do is put this code on my config page?

http://www.phpfastcache.com/

I downloaded the files. On the examble.php

what do iput on $contents?

<?php
include("php_fast_cache.php");
phpFastCache::$storage = "auto";
// ready ?
// check in case first
$content = phpFastCache::get("keyword1");
if($content == null) {
// for testing
echo "This is not caching, page is render with lot queires and slow speed <br>";
// do what you want, like get content from cURL | API | mySQL Query and return result to $content
$content = file_get_contents("http://www.phpfastcache.com/testing.php");
// rewrite cache for other request in 5 seconds
phpFastCache::set("keyword1",$content,5);
} else {
// use cache
// node
echo "THIS TIME USE CACHE, FAST! <br>";
}
echo "TRY F5 to refesh the page to see new SPEED with Cache!<br>";
echo $content;

why is this line? $content = file_get_contents("http://www.phpfastcache.com/testing.php");

  • 写回答

2条回答 默认 最新

  • dongqun9403 2014-12-16 22:43
    关注

    what do iput on $contents?

    Contents would be the data that you are attempting to save. I.E

    $contents = "Hello World!";

    Or...

    $contents = ['video_url' => 'youtube.com/v?=1234534'];

    why is this line?

    That line is simply retrieving the contents of testing.php into a string.

    From what it sounds like, any sort of PHP caching wont do any good if your main issue is because of embedded videos... If however you are displaying one video at a time on a page and the videos are hidden because of a Javascript. I would recommend using PHP to load the embedded video based on the URL instead.

    I.E - Assuming if your not using a database to display videos.

    Website Address http://www.mywebsite.com/mypage/?v=1

    <?php //INSERT THIS WHERE YOU WANT A VIDEO TO DISPLAY.
    switch($_GET['v'])
    {
         case 1:
            echo '<YOUTUBE EMBEDDED HTML HERE>';
         break;
    
         case 2:
            echo '<VIMEO EMBEDDED HTML HERE>';
         break;
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示