위와같이, Webserver에서 php파서와같이 코드를 해석한후 SQLServer로 데이터를 요청하고, 정렬하여 html포맷으로 웹클라이언트에게 응답해줍니다.
구현목적에 따라 달라지겠지만, 게시판과같이 실시간으로 출력해줘야하는 형태가 아니라면 비효율적일수있겠죠.
이에, 아래와같이 동적처리를마친 파일을 cache 저장합니다.
5분간은 접속자가 몇명이든지간에, SQL에게 데이터를 묻지않고도 php와 협력하여 파싱을 하지않고도 웹서버는 그냥 캐싱된파일을 읽어와 출력해주면 되겠죠.
서버부하와 속도는 당연히 빨라질것입니다.
쉽게 말하면, 파일로 저장해두고 5분에 한번 갱신해주는겁니다.
1분 접속자가 1천명이라치면 5천번의 이벤트가 1번으로 주는거겠죠.
(?
$reqfilename = "index";
$cachefile = "cache/".$reqfilename.".xanadu";
$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;
}
// start the output buffer
ob_start();
?)
Here is Page-Content home
(?
$fp = fopen($cachefile, 'w'); // open the cache file for writing
fwrite($fp, ob_get_contents()); // save the contents of output buffer to the file
fclose($fp); // close the file
// Send the output to the browser
ob_end_flush();
?)