我知道glob()
函数很慢但是它如何与GLOB_ONLYDIR
参数一起使用?它仍会检查每个文件,还是会使用某些索引或其他什么?
答案 0 :(得分: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必须检查每个文件,无论它是否仅询问非目录文件。