라이브러리

[PHP_CONFIG] opcache.file_cache_only - OPcache에서 파일 캐시 전용 모드 사용 여부




PHP OPcache

PHP OPcache는 PHP의 컴파일러 캐시를 제공하는 모듈입니다. OPcache는 PHP 스크립트를 컴파일하여 캐시에 저장하여 다음 요청시 빠르게 실행할 수 있도록 도와줍니다. OPcache는 PHP 5.5부터 기본적으로 포함되어 있습니다.

OPcache 설정

OPcache 설정은 PHP의 `php.ini` 파일에서 할 수 있습니다. `opcache` 섹션에 있는 설정을 확인하면 다음과 같습니다.

#hostingforum.kr
ini

[opcache]

; Enable or disable OPcache

opcache.enable=1



; The directory under which the user data will be stored

opcache.dir="/tmp/opcache"



; The cache file name

opcache.file_cache_only=0



opcache.file_cache_only

`opcache.file_cache_only` 설정은 OPcache 캐시를 파일로만 저장할지, 또는 메모리( RAM )에 저장할지 결정합니다. 기본값은 `0` 이며, 메모리에 캐시를 저장합니다.

파일 캐시

`opcache.file_cache_only` 설정을 `1` 로 설정하면 OPcache 캐시를 파일로만 저장합니다. 이 경우, 캐시 파일은 `opcache.dir` 설정에 지정된 디렉토리에 생성됩니다.

#hostingforum.kr
ini

[opcache]

; ...

opcache.file_cache_only=1



예제

파일 캐시를 사용하는 예제는 다음과 같습니다.

#hostingforum.kr
php

<?php

// test.php

function test() {

    echo "Hello, World!";

}



test();



`opcache.file_cache_only` 설정을 `1` 로 설정하고, `test.php` 파일을 실행한 후, 캐시 파일을 확인해 보면 다음과 같습니다.

#hostingforum.kr
bash

$ ls /tmp/opcache/

test.php



이제, `test.php` 파일을 수정하고, 다시 실행하면 캐시 파일이 업데이트됩니다.

#hostingforum.kr
php

// test.php

function test() {

    echo "Hello, PHP!";

}



#hostingforum.kr
bash

$ php test.php

Hello, PHP!

$ ls /tmp/opcache/

test.php



메모리 캐시

`opcache.file_cache_only` 설정을 `0`으로 설정하면 OPcache 캐시를 메모리에 저장합니다. 이 경우, 캐시 데이터는 메모리에만 저장되며, 파일로 저장되지 않습니다.

#hostingforum.kr
ini

[opcache]

; ...

opcache.file_cache_only=0



예제

메모리 캐시를 사용하는 예제는 다음과 같습니다.

#hostingforum.kr
php

<?php

// test.php

function test() {

    echo "Hello, World!";

}



test();



`opcache.file_cache_only` 설정을 `0`으로 설정하고, `test.php` 파일을 실행한 후, 캐시 데이터를 확인해 보면 다음과 같습니다.

#hostingforum.kr
bash

$ php -r "var_dump(opcache_get_status());"

array(5) {

  ["cache_hits"]=>

  int(1)

  ["cache_misses"]=>

  int(1)

  ["cache_size"]=>

  int(32)

  ["memory_usage"]=>

  int(32)

  ["num_cached_files"]=>

  int(1)

}



이제, `test.php` 파일을 수정하고, 다시 실행하면 캐시 데이터가 업데이트됩니다.

#hostingforum.kr
php

// test.php

function test() {

    echo "Hello, PHP!";

}



#hostingforum.kr
bash

$ php -r "var_dump(opcache_get_status());"

array(5) {

  ["cache_hits"]=>

  int(1)

  ["cache_misses"]=>

  int(1)

  ["cache_size"]=>

  int(32)

  ["memory_usage"]=>

  int(32)

  ["num_cached_files"]=>

  int(1)

}



결론

`opcache.file_cache_only` 설정은 OPcache 캐시를 파일로만 저장할지, 또는 메모리( RAM )에 저장할지 결정합니다. 파일 캐시는 캐시 데이터가 파일로 저장되며, 메모리 캐시는 캐시 데이터가 메모리에만 저장됩니다. 이 설정을 사용하여 OPcache 캐시를 최적화할 수 있습니다.
  • profile_image
    나우호스팅 @pcs8404 

    호스팅포럼 화이팅!

    댓글목록

    등록된 댓글이 없습니다.

  • 전체 394건 / 10 페이지

검색

게시물 검색