메뉴 건너뛰기

infra

웹캐시 파일, 생성 알고리즘....

박영식2004.03.05 20:40조회 수 2481댓글 0

    • 글자 크기
알고리즘이라고 까지하면, 거창하고,,,

ob_start() / ob_get_contents() /ob_clean()을 이용해서, 웹 페이지를 생성하여, 그것을 file로 저장하는 방법입니다.
일반적으로 알고 있는, fopen / fread는 자체 파일 읽기인데, ob_start() .... 을 쓰면, 클라이언트에서 보이는 화면, 즉,, 인터프리터된 결과를 얻어서 저장하게 되는 것이죠. 웹캐시 방법을 이용하기 위해 쓴 함수로, db connection이 잦은 곳에서 query를 줄이고, webpage를 액세스하게 하는 방법입니다.

웅... 유용합니다. test해 보시길...

require는 인터프리터하고자 하는 파일이고, index.html은 기록된 파일입니다.
header()함수로, 작성된 파일로 이동합니다.
쉽죠???

<?
$var1 = "some value";
$var2 = "some other value";
/*start the output buffering*/
ob_start();
/*include the tempate file*/
require("index_c.php");
/*get the contenst of the output buffer*/
$data = ob_get_contents();
/*write the contents to a file*/
$fp = fopen("index.html","w");
fwrite($fp,$data);
fclose($fp);
/*clear the output buffer*/
ob_clean();
header('Location:index.html') ;
/*display some other page - like "you have successfully written a file" or something*/
//require("return_url.php");
?>
박영식 (비회원)
    • 글자 크기
테크노트 ----> 킴스보드 db직접 넣기 (by 박영식) 세미나 테이블 만들기 (by 박영식)

댓글 달기

이전 1 ... 2 3 4 5 6 7 8 9 10 11다음
첨부 (0)
위로