2010-03-02 5 views
6

나는 웹 사이트 캐싱에 대해 저에게 말할 수있는 모든 유익한 정보를 찾고 있습니다 ... 저는 PHP로 작업 중이므로 누구나 제게 PHP로 캐싱하는 방법을 설명 할 수 있습니다.php를 사용하여 페이지 캐싱

+0

참조하십시오 http://stackoverflow.com/questions/2279316/beginner-data-caching-in-php – fire

답변

7

PHP는 출력 버퍼링의 형태로 동적 캐싱에 대한 매우 간단한 솔루션을 제공합니다. 가장 많은 트래픽을 생성하는 사이트의 첫 페이지는 최근 5 분 이내에 캐시 된 경우 캐시 된 복사본에서 제공됩니다.

<?php 

    $cachefile = "cache/".$reqfilename.".html"; 
    $cachetime = 5 * 60; // 5 minutes 

    // Serve from the cache if it is younger than $cachetime 
    if (file_exists($cachefile) && (time() - $cachetime 
    < filemtime($cachefile))) 
    { 
    include($cachefile); 
    echo "<!-- Cached ".date('jS F Y H:i', filemtime($cachefile))." 
    -->n"; 
    exit; 
    } 
    ob_start(); // start the output buffer 
?> 

.. Your usual PHP script and HTML here ... 

<?php 
    // open the cache file for writing 
    $fp = fopen($cachefile, 'w'); 

    // save the contents of output buffer to the file 
    fwrite($fp, ob_get_contents()); 

    // close the file 

    fclose($fp); 

    // Send the output to the browser 
    ob_end_flush(); 
?> 

이 간단한 캐시 유형,

당신이 여기 볼 수

http://www.theukwebdesigncompany.com/articles/php-caching.php

당신은 사용할 수 있습니다 스마티 캐시 기술을 내가 '

http://www.nusphere.com/php/templates_smarty_caching.htm

1

있다 오히려 놀랐다. f 지금까지의 응답은 PHP가 실행되는 서버보다 어디에서나 OTHER과 같은 캐싱 가능성을 처리 한 것으로 보입니다.

프록시 및 브라우저가 이전에 다시 참조 할 필요없이 원본 콘텐츠를 다시 사용할 수 있도록 HTTP에는 많은 기능이 있습니다. 너무 많이 그래서 나는 S.O.에서 이것을 대답하려고하지 않을 것입니다. 댓글.

소개에 대한 내용은 tutorial을 참조하십시오.

C.