페이지캐슁 - 최근글을 캐쉬로 > 서버관리 Tip

본문 바로가기
 

페이지캐슁 - 최근글을 캐쉬로

페이지 정보

작성자 no_profile 차동박 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 8,894회 작성일 08-04-18 16:05

본문

페이지캐슁 - 최근글을 캐쉬로   
 글쓴이 :  아빠불당 (222.♡.219.211)  조회 : 516  추천 : 1   
첨부 파일을 /home2.php로 업로드
/preload/cache 디렉토리를 생성후 707로 권한을 부여
필요한 곳에서 /home2.php 파일을 호출

(로직)
$bo_table 테이블에 업데이트가 있는 경우 최글글 캐쉬 파일의
날짜와 비교해서, 업데이트가 최근이고 파일을 수정한지 120초가
지났으면 캐쉬파일을 새로 생성.
* 스크랩의 경우에는 빈도가 많지 않아서 굳이 파일의 수정날짜를
체크하지 않아도 되지만, 일반적인 테이블의 경우에는 업데이트가
빈번 할 수 있으므로, 매 업데이트마다 캐쉬를 만들지 않고 최소
120 sec마다 캐쉬 파일을 만들어 줍니다.

home2.php는 제가 쓰는 코드이므로 잘 읽어보시면 금방 이해가실거에요^^

/home2.php

<?
include_once("./_common.php");
include_once("$g4[path]/lib/latest.lib.php");

$g4['title'] = "";
include_once("./_head.php");

?>
<style>
.latest_border { border:3px #e0e0e0 solid; padding:7px; }
.top_box_border { border:3px #E3F0BA solid; padding:10px; line-height:150%; }
</style>

<script language="javascript" src="./js/sideview.js"></script>

<?
// 캐쉬 파일을 만들어주는 함수
function show_latest_cache($skin_dir="basic", $bo_table, $rows=10, $subject_len=40, $options="")
{
    global $g4, $mysql_db;

    // 테이블의 마지막 업데이트 일시 가져오기
    $tmp_write_table = $g4['write_prefix'] . $bo_table; // 게시판 테이블 전체이름
    $sql = "SHOW TABLE STATUS FROM $mysql_db WHERE name = '$tmp_write_table'";
    $result = sql_fetch($sql);
    $table_update_ut = strtotime($result['Update_time']);

    $filename_ch = "$g4[path]/preload/cache/bo_$bo_table.cache.php";

    // 파일 수정 일시 가져오기
    $file_modify_ut = @filemtime("$filename_ch");

    // 파일 수정후 지나간 시간
    $pass_ut = time() - $file_modify_ut;

    // Table Update Unixtime : $table_update_ut
    // File Modify Unixtime  : $file_modify_ut

    if( $table_update_ut > $file_modify_ut and $pass_ut > 120) // 파일 업데이트 이후에 DB가 변경되었을 때
    {
        // 페이징 캐쉬 스크립트
        ob_start();
        // latest($skin_dir="", $bo_table, $rows=10, $subject_len=40, $options="")
        echo latest("basic", "$bo_table", $rows, $subject_len, $options);

        $cache_out = ob_get_clean();
 
        // 파일이 없는 경우 파일을 생성
        if ( !file_exists("$filename_ch") ) {
            fclose( fopen("$filename_ch", "w") );
        }

        // 파일에 저장
        $fp = fopen("$filename_ch", "w");
        fwrite($fp, $cache_out);
        fclose($fp);
    }

    require_once("$filename_ch");
}
?>

<table border=0 cellspacing=0 cellpadding=0 width="100%">
<tr>
 <td width="50%" style="padding-right:5px;" valign=top>
  <!-- 왼쪽 시작 -->
  <table border=0 cellspacing=0 cellpadding=0 width="100%">
  <tr>
  <td>
    <?=show_latest_cache("basic", "qna", 12, 40, "4,40");?>
    <?=show_latest_cache("basic", "qna_size", 8, 40, "4,40");?>
  </td>
  </tr>
  <tr>
  <td height=10></td>
  </tr>
 
  </tr>
  <tr>
  <td>
    <?=show_latest_cache("basic", "saleinfo", 10, 40, "4,40");?>
  </td>
  </tr>
  <tr>
  <td height=10></td>
  </tr>

  <tr>
  <td>
    <?=show_latest_cache("basic", "hotdeal", 4, 40, "4,40");?>
  </td>
  </tr>
  <tr>
  <td height=10></td>
  </tr>
 
  <tr>
  <td>
    <?=show_latest_cache("basic", "gift", 4, 40, "4,40");?>
  </td>
  </tr>
  <tr>
  <td height=10></td>
  </tr>

  <tr>
  <td>
    <?=show_latest_cache("basic", "09", 15, 40, "4,40");?>
    <?=show_latest_cache("basic", "flea", 15, 40, "4,40");?>
  </td>
  </tr>
  </table>
  <!-- 왼쪽 끝 -->
 </td>
 <td width="50%" style="padding-left:5px;" valign=top>
  <!-- 오른쪽 시작 -->
  <table border=0 cellspacing=0 cellpadding=0 width="100%">
    <tr>
  <td>
        <?=show_latest_cache("basic", "showup", 12, 40, "4,40");?>
        <?=show_latest_cache("basic", "sell", 12, 40, "4,40");?>
  </td>
  </tr>
  <tr>
  <td height=10></td>
  </tr>
   
  <tr>
  <td>
      <?=show_latest_cache("basic", "buytalk", 12, 40, "4,40");?>
    <?=show_latest_cache("basic", "usetalk", 12, 40, "4,40");?> 
  </td>
  </tr>
  <tr>
  <td height=10></td>
  </tr>

  <tr>
  <td>
        <?=show_latest_cache("basic", "buybook", 10, 40, "4,40");?>
        <?=show_latest_cache("basic", "notice", 10, 40, "4,40");?>
  </td>
  </tr>
 
  </table>
  <!-- 오른쪽 끝 -->
 </td>
</tr>
</table>

<?
include_once("./_tail.php");
?>

댓글목록

등록된 댓글이 없습니다.

Total 159건 9 페이지
서버관리 Tip 목록
번호 제목 글쓴이 조회 날짜
15 no_profile 차동박 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9365 06-29
14 no_profile 차동박 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9463 06-27
13 no_profile 차동박 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 13882 06-20
12 no_profile 차동박 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10306 06-20
11 no_profile 차동박 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9571 06-20
10 no_profile 차동박 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9602 06-20
9 no_profile 차동박 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9658 06-20
8 no_profile 차동박 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9752 06-20
7 no_profile 차동박 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9453 06-13
6 no_profile 차동박 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 10738 04-18
5 no_profile 차동박 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 17831 04-18
열람중 no_profile 차동박 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 8895 04-18
3 no_profile 차동박 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9092 04-14
2 no_profile 차동박 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 9041 04-14
1 no_profile 차동박 쪽지보내기 메일보내기 자기소개 아이디로 검색 전체게시물 15385 04-14
게시물 검색