PHP 파일에서 상수 묶음의 정확한 로딩 시간을 측정하고 싶습니다. I는 4 가지 방법 선택한 : 상수로드 벤치 마크
- 을 (쓰기 파일 및 부하로 json_encoded 값 그들을 먼저 I 이러한 방법으로 4 개 가지 파일을 생성하고 모든 5000 임의의 이름 및 값 쌍 (동일한 값)로 가득
file_get_contents 및 json_decode)를 사용.
PHP로로드하려고 시도했지만로드 시간을 측정하기 위해 microtime
함수를 사용했지만 결과가 조금 이상하게 보입니다! 나는 새로운 생성 된 파일의 세트로 test.php
를로드 할 때
// array
$time['array']['start'] = microtime(true);
$config_a = include('conf_array.php');
$time['array']['end'] = microtime(true);
// class
$time['class']['start'] = microtime(true);
include('conf_class.php');
$config_c = new Config();
$time['class']['end'] = microtime(true);
// define
$time['defin']['start'] = microtime(true);
include('conf_define.php');
$time['defin']['end'] = microtime(true);
// json
$time['json']['start'] = microtime(true);
$config_j = json_decode(file_get_contents('conf_json.json'));
$time['json']['end'] = microtime(true);
foreach ($time as $name => $item) {
echo $name . ": " . (($item['end'] - $item['start']) * 1000) . " units.";
}
, 나는 이러한 결과를 얻을 것이다 : 이것은 내 test.php
파일입니다
Array: 7.9629421234131 units.
Class: 6.5279006958008 units.
Defin: 19.877910614014 units.
Json: 4.4741630554199 units.
을하지만 난 (F5) 새로 고침 버튼을 쳤을 때, 결과가 바뀔 것이다! 페이지를 새로 고친 후 동일한 샘플의 결과는 다음과 같습니다.
Array: 1.7659664154053 units.
Class: 2.467155456543 units.
Defin: 6.4060688018799 units.
Json: 4.9409866333008 units.
그런 다음 순서는 더 이상 변경되지 않습니다. PHP 파일 (json을 제외한 모든 파일)은 두 번 이상로드 할 때 더 빨리로드됩니다. 아파치를 (PHP와 함께) 다시 시작하면 똑같은 일이 일어날 것이다.
왜 이런 일이 발생했는지 궁금합니다. 어떤 종류의 캐싱과 관련이 있습니까?