dongtazu3080 2014-12-14 06: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?

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

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

  • 写回答

2条回答 默认 最新

  • dongqun9403 2014-12-16 14: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

    1. <?php //INSERT THIS WHERE YOU WANT A VIDEO TO DISPLAY.
    2. switch($_GET['v'])
    3. {
    4. case 1:
    5. echo '<YOUTUBE EMBEDDED HTML HERE>';
    6. break;
    7. case 2:
    8. echo '<VIMEO EMBEDDED HTML HERE>';
    9. break;
    10. }
    11. ?>
    评论
  • dousha7645 2014-12-29 06:38
    关注

    the urls are stored in the database. so if i want to cache the url. i ll write this

    include("php_fast_cache.php");
    

    phpFastCache::$storage = "auto";

    $content = phpFastCache::get($url);

    echo "TRY F5 to refesh the page to see new SPEED with Cache! "; echo $content;

    $url = https://www.youtube.com/watch?v=iVoRw5qWc2o

    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部