2013-03-12 10 views
-2

나는 glob() 함수가 꽤 느리지 만 인수가 GLOB_ONLYDIR인데 어떻게 작동할까요? 그것은 여전히 ​​모든 파일을 검사 할 것인가 아니면 어떤 인덱스를 사용할 것인가?glob() 함수는 어떻게 작동합니까?

+1

소스를보고 나면 ['ext/standard/dir.c : 511-518'] (https://github.com/php/php-src/blob/master/ext/standard/dir.c) # L511-518), PHP가 각 파일을 디렉토리인지 확인해야합니다. 그러나 질문은 이제 닫혀 있기 때문에 나는 대답 할 수 없다. –

답변

1

the source에서 상대 :

/* we need to do this everytime since GLOB_ONLYDIR does not guarantee that 
* all directories will be filtered. GNU libc documentation states the 
* following: 
* If the information about the type of the file is easily available 
* non-directories will be rejected but no extra work will be done to 
* determine the information for each file. I.e., the caller must still be 
* able to filter directories out. 
*/ 
if (flags & GLOB_ONLYDIR) { 
    struct stat s; 

    if (0 != VCWD_STAT(globbuf.gl_pathv[n], &s)) { 
     continue; 
    } 

    if (S_IFDIR != (s.st_mode & S_IFMT)) { 
     continue; 
    } 
} 

그래서 PHP에 관계없이 만이 아닌 디렉토리 파일을 요청 여부, 각 파일을 확인할 수 있습니다.

관련 문제