웹마스터 팁

APC(Alternativ PHP Cache) 사용법( php 캐쉬 플러그인 )

APC라는 프로그램을 들어 보고 난 후에 제 시스템에 설치를 했습니다.

제 시스템 사양은:

CPU: 셀러론 300A
Memory: 384M
OS: Redhat 7.1
WebServer: Apache/1.3.20
phpVersion: 4.0.6
MySQL: 3.23.42
이정도 입니다. 보편사양이죠?

APC를 사용한지 몇주 정도 됩니다.
php로 만든 홈페이지에 상당한 속도 향상을 볼 수 있었습니다.
서버에 설치하고 난 후 체감속도가 달랐습니다. ^_^

외국 여러사이트에서도 이 프로그램을 소개를 해놓았는데.
내용은 Zend Cache라는 사용프로그램과 비슷하다는 것입니다.
문론 Zend Cache는 평가판을 사용해 보실 수 있습니다만,
일반 유저들이 무슨 돈이 있어서 상용을 구매 할 수 있겠습니까?

각설하고 설치법은 간단합니다.


1:  http://apc.communityconnect.com/download.html
에서 다운을 받는다.

2: /tmp 나 기타 디렉토리에 풀어봅니다.

3: [1006 root@www apc-1.1.0pl1]#./configure --enable-apc --with-php-config=/usr/local/lib/php
   [1006 root@www apc-1.1.0pl1]#make

라고 합니다.
그럼 컴파일이 됩니다.

4. [1006 root@www apc-1.1.0pl1]#cp php_apc.so /usr/local/lib/php/extensions/php_apc.so
카피를 합니다.


5. php.ini를 엽니다.
아래와 같이 편집합니다.

zend_extension="/usr/local/lib/php/extensions/php_apc.so"
apc.mode=shm
apc.relative_includes=1
apc.check_mtime=1
apc.shm_segment_size=25971520 ; 25 MB
apc.idle=900 ; removed from cache if idle for 15 minutes
apc.hash_buckets=256
apc.cachedir=/var/apc_php/

저장하고 편집기를 닫습니다.

5. 웹서버를 다시 실행 시켜줍니다.
[1015 root@www extensions]# /etc/rc.d/init.d/httpd restart
Shutting down httpd:                                       [  OK  ]
Starting httpd:                                            [  OK  ]

6. 웹페이지 root에서 apcinfo.php라는 파일을 만들어서 아래와 같이 편집해보세요.
<?
apcinfo();
?>

저장하시고 난 후 웹브라우즈에서 불러봅니다.
그러시면 해당되는 정보를 보실 수 있습니다.
<?
phpinfo();
?>
로 보시면
with APC Caching v1.1.0, Copyright (c) 2000-2001 Community Connect Inc., by
                                        Dan Cowgill and George Schlossnagle
라는 문구를 보실 수 있습니다.

그럼 완성.....^_^

7. apc.mode 옵션에는 2가지가 있습니다.
SystemV semaphores and shared memory (shm모드)
memory mapped files mode (mmap모드)
가 있습니다.
차이점은 원문으로 올립니다. 참고하세요.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We wrote two implementations, one using SystemV semaphores and shared memory and the
other using memory-mapped files and file locking, for portability between Unix systems
and for testing. Both support all of the basic cache operations, but they are not functionally
identical. For example, the shared memory implementation (shm) is capable of much finer control
of cached objects than the memory-mapped file implementation (mmap).

Here is a list of pros and cons for each:


   shm
        pros:
            - supports per object time-to-live values
            - cache statistics available for entire webserver
        cons:
            - as with all programs that use SystemV semaphores, it has the
              potential to "leak" semaphores

    mmap
        pros:
            - greater visibility into the inner workings of the cache
            - can be used as a general compiler, because the cached objects
              are stored as files
        cons:
            - may require many open files
            - cache statistics are per process, not per host
            - cache management is more difficult


Our internal tests have shown little difference in speed between the two implementations under
typical conditions. There are unusual situations, however, under which one implementation will
perform better than the other. For example, in common situations, shm tends to perform slightly
better; but if a webserver serves a very small number of pages, mmap may perform better because it
reduces contention between the webserver processes. If you need optimal performance, our advice
is to try both implementations and make a decision based on benchmark data.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


*주의: 1. Zend optimizer과는 같이 동작을 하지 않더군요.
          Php.ini에서 Zend Optimizer관련은 주석처리 하세요.

       2. 현재 저 시스템은 이상없이 돌아갑니다.
          제로보드도 잘보이고 아무 이상이 없습니다만, 다른 시스템은 어떨지 모르겠네요.
  

*사족: 1. 컴파일이 안되시는 분 위에 첨부파일 php_apc.so를 다운받으셔서.
          /usr/local/lib/php/extensions/
          으로 복사해서 넣어세요.
          그러고 난 다음 chmod 755 ./php_apc.so
          라고 하신 다음 5번 과정을 실행하시면 됩니다.

       2. 정확한 성능비교는 못해 보았습니다.
          성능비교 해 보신분은 사용기 올려주시면 감사하겠네요.
          그리고 각 모드별 특징 아시는 분은 가르쳐 주시면 고맙겠네요.
        
그럼..