처리를 위해 아파치 액세스 로그에서 읽는 PHP 코드 스 니펫이 있습니다. 이 몇 줄의 코드를 제거 했는데도 여전히 누수가 있습니다. 메아리 memory_get_usage()가 매번 11MB를 계속보고하더라도 PHP 프로세스는 점점 더 많은 메모리를 차지합니다.이 PHP 코드 조각의 메모리 누수는 어디에 있습니까?
우분투 12 컴퓨터에서 PHP 5.3.6을 실행 중입니다. 문제는 우분투에서 PHP 5.2로 사라집니다.
$logDir = opendir(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tempLog');
while (($file = readdir($logDir)) !== false) {
echo($file . PHP_EOL);
$filePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'tempLog' . DIRECTORY_SEPARATOR . $file;
$fhandle = fopen($filePath, 'r');
fseek($fhandle, 0);
while(!feof($fhandle)) {
$line = fgets($fhandle);
}
fclose($fhandle);
echo('Finished reading!' . PHP_EOL);
echo('Memory usage: ' . memory_get_usage() . PHP_EOL . PHP_EOL);
system('cat /proc/' . getmypid() . '/status | grep VmSize');
}
편집 :이 스크립트에서 추가 샘플 출력 : EDIT2 : 추가 VM 크기
access.log.2
Finished reading!
Memory usage: 11303616
VmSize: 54972 kB
access.log.19
Finished reading!
Memory usage: 11303616
VmSize: 55896 kB
access.log.23
Finished reading!
Memory usage: 11303616
VmSize: 81372 kB
access.log.41
Finished reading!
Memory usage: 11303616
VmSize: 93120 kB
access.log.31
Finished reading!
Memory usage: 11303616
VmSize: 107508 kB
access.log.28
Finished reading!
Memory usage: 11303616
VmSize: 112128 kB
access.log.5
Finished reading!
Memory usage: 11303616
VmSize: 112920 kB
..
Finished reading!
Memory usage: 11303592
VmSize: 112920 kB
.
Finished reading!
Memory usage: 11303592
VmSize: 112920 kB
메모리 누수가있을 수 있습니다 어떤 아이디어? 내가 어떻게 그것을 피할 수 있을까?
WAG로서 'while'루프가 비난받는 것 같아요. 아마도'fgets'와 관련이있을 것입니다. 아내와 여자 친구로 – zzzzBov
? http://en.wikipedia.org/wiki/WAGs – 75inchpianist
Apache 액세스 로그가 매우 커질 수 있습니다. 구문 분석하려는 로그의 크기는 얼마나 큽니까? –