
1 imcaibaozi 2013 年 5 月 27 日 is_file() will return false if the given path points to a directory. file_exists() will return true if the given path points to a valid file or directory. http://stackoverflow.com/questions/792899/is-file-or-file-exists-in-php |
2 kasp OP 同样是文件的情况下。 @imcaibaozi |
3 kasp OP $xpf = dirname(dirname(__FILE__)).'/works/xpf';//xpf目录是XP共享,通过mount挂载到linux目录 $r = $xpf.'/config/cache.php'; var_dump(file_exists($r));//true var_dump(is_file($r));//false |
4 imcaibaozi 2013 年 5 月 27 日 is_link() 呢? |
5 vietor 2013 年 5 月 27 日 猜想is_file读了file attributes来判断类型,应该比file_exists慢 |
6 Feobe 2013 年 5 月 27 日 php::is_file - total self: 0.5ms total cum: 0.5ms calls: 10,000 php::file_exists - total self: 41ms total cum: 41ms calls: 10,000 is_file却快了N倍 在php底层源码里,也确是这样 @vietor |
7 fatpa 2013 年 5 月 28 日 一个判断文件是否存在,一个断是否为文件吧…… |
8 vietor 2013 年 5 月 28 日 @Feobe 的确我错了。 之前我考察过这两个函数,我忘记了结论。经过你的数据,可以想起一部分:file attributes验证文件存在的方式最快,file_exists好像调用了别的处理,是什么想不起来了。 |
9 imcaibaozi 2013 年 5 月 28 日 @kasp 最后到底是因为什么呢@@ |
10 kasp OP @imcaibaozi 不知道呢,应该需要读下PHP源码看下两个函数实现的方式有什么区别吧。 |