응용개발

PHP PEAR extension Cache-Lite 를 이용한 응용 프로그램 최적화

by 웁쓰 posted Jul 01, 2009
웹개발을 하다 보면 특정 부분에 대해서 응답 속도(response time) 나 처리량(througput) 에 대한 문제점이 발생 한다.

대부분의 웹프로그램은 DB 시스템의 영향을 받게 되는데 최대한 DB Access를 줄인다면 응답 속도나 처리량을 늘일수 있는 방법이 있어 소개 한다.

PHP PECL Cache-Lite을 이용하면 PHP에서도 Cache 기능을 사용할 수 있다.(현재 테스트 된 버전은 1.7.7 이다)
홈페이지 http://pear.php.net/package/Cache_Lite/

설치 방법
$pecl install Cache_Lite

업그래이드 방법
$pecl upgrdate Cache_Lite


샘플 코드 test_cache.php
<? require_once('Cache/Lite.php'); // Set a id for this cache $id = '123'; // Set a few options $options = array( 'cacheDir' => '/tmp/', 'lifeTime' => 3600 ); // Create a Cache_Lite object $Cache_Lite = new Cache_Lite($options); // Test if thereis a valide cache for this id if ($data = $Cache_Lite->get($id)) { echo " Cache hit !"; echo $data; // Content is in $data } else { // No valid cache found (you have to make the page) echo " Cache miss !"; // Put in $data datas to put in cache $con = cubrid_connect ("localhost", 33000, "demodb","dba",""); $req = cubrid_execute ($con, "select 1 as "id" , 2 as "name" from db_root"); if ($req) { if ($row = cubrid_fetch ($req, CUBRID_OBJECT)) { echo $row->id; echo $row->name; $data = $row->id; $Cache_Lite->save($data,'123'); } } cubrid_close_request ($req); cubrid_disconnect ($con); } ?>

cache 적용전

cache 적용후


Articles

5 6 7 8 9 10 11 12 13 14