-2

我知道这个glob()函数很慢,但它如何与GLOB_ONLYDIR参数一起工作?它还会检查每个文件还是会使用一些索引或其他什么?

4

1 回答 1

1

源码

/* 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 必须检查每个文件,不管它是否只要求非目录文件。

于 2013-03-13T15:41:32.253 回答