Some reminiscences, some memories

Just another boring day
« 使用日立 Feature Tools 软盘镜像解决 Ubuntu 磁盘的 load/unload 问题
长此以往,国将不国 »

23

Sep

Zend_Loader::isReadable 和 is_readable 的区别

mikespook 

以前分析过 Zend Framework 1.0 的 Zend_Loader;php 内建函数 is_readable 本质上就是调用 filestat.c 的 php_stat 函数,这个在前几天关于 file_exists 和 is_file 的那个 post 中有说过。
今天在群上跟番茄吹水,说起来这个东西。于是又混一篇小记随便吹吹。
以下所有内容,45%是吹水,45%是猜测,10%是从代码中看出来的。

Zend_Loader:isReadable() 的代码如下:

150 /**
151 * Returns TRUE if the $filename is readable, or FALSE otherwise.
152 * This function uses the PHP include_path, where PHP’s is_readable()
153 * does not.
154 *
155 * @param string $filename
156 * @return boolean
157 */
158 public static function isReadable($filename)
159 {
160 if (!$fh = @fopen($filename, ‘r‘, true)) {
161 return false;
162 }
163 @fclose($fh);
164 return true;
165 }

可以看到,通过 fopen 来判断是否能访问指定文件。并且 fopen 的第三个参数为 true,也就是说允许判断 include_path 中的文件。这个方法有个显而易见的好处,除了可以判断 include_path 的文件外,还可以使用 http://foobar 或者 ftp://foobar 的 php stream 方式来判断是否可读。也就是说支持远端文件。

而 is_readable 从 php_stat 这个 c 函数的内容上可以看出,是不支持远端文件的。最多支持 file:// 而已。
不过 is_readable 是具有缓存的,也就是说可以用更小的代价去获得文件的访问属性。而 Zend_Loader::isReadable 不但要 fopen,还要 fclose 代价不能说不大了。

至于如何取舍,其实就看具体的需求了。

This entry was posted on Tuesday, September 23rd, 2008 at 07:54 and is filed under PHP, Zend Framework. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

Trackback URI | Comments RSS

 

September 2010
M T W T F S S
« Aug    
 12345
6789101112
13141516171819
20212223242526
27282930  

Recent Comments

  • cbf107 on 我们精通精通
  • mikespook on 我们精通精通
  • == on 我们精通精通
  • 老熊 on 关于Web编程异步模型的白日梦
  • Some reminiscences, some memories » Blog Archive » Akihabara 指南目录 on Akihabara 指南

Tags

乱码 协程 地震 备案 安装 广州 异步 性能 我爱发明 扯淡 招聘 游戏 漏洞 翻译 豆瓣 39.com Adobe akihabara config countdown Demo Flash game engine golang google html5 issue linux Micromedia MongoDB mysql NetBeans nginx NoSQL oracle PHP phpunit Python trac ubuntu xdebug xml xubuntu yield Zend Framework

Blogroll

  • Blog on 27th Floor
  • DBA notes
  • Tim[后端技术]
  • 唐海燕
  • 小众音乐
  • 抚琴居
  • 某人的栖息地
  • 番茄’s Blog
  • 網站製作學習誌
  • 纸老虎传媒

Old friends

  • cbf107

Only

  • 媚惑桃花

OurPNP

  • Biaoest:标的最高级
  • flexsns-官方博客
  • PNP University
  • PNP街坊
  • smallfish 鱼哥的窝子
  • 冰山日志
  • 墙外的光神V5
  • 夜雨's Blog
  • 小冬kobe
  • 小路的奇异世界
  • 广州萌芽工作室
  • 老甘blog
  • 赖勇浩的编程私伙局

Meta

  • Log in
  • Entries RSS
  • Comments RSS
  • WordPress.org

Powered by WordPress
mikespook.com 粤ICP备09065095号