$handle = fopen($filename, "rb");
$contents = fread($handle, filesize($filename));
fclose($handle);
// vs. much simpler
file_get_contents('./somepic.gif');
?>
关于引用的技巧
引用可以:
- 简化对复杂结构数据的访问
- 优化内存使用
<?php
$a['b']['c'] = array();
// slow 2 extra hash lookups per access
for ($i = 0; $i < 5; ++$i)
$a['b']['c'][$i] = $i;
// much faster reference based approach
$ref =& $a['b']['c'];
for ($i = 0; $i < 5; ++$i)
$ref[$i] = $i;
?>
<?php
$a = 'large string';
// memory intensive approach
function a($str){
return $str.'something';
}
// more efficient solution
function a(&$str){
$str .= 'something';
}
?>
==============================================
参考资料
http://ilia.ws
Ilia 的个人网站,Blog,他参与的开发以及出版的一些稿物链接等等。
http://ez.no
eZ components 官方网站,eZ comp 是针对 PHP5 的开源通用库,以效率为己任,Ilia 也参与了开发。
http://phparch.com
php|architect,不错的 php 出版商/培训组织。买不起或者买不到的话,网上可以下到很多经典的盗版。
http://talks.php.net
PHP 会议上的演讲合集,现在还不是很丰富,不过内容都是让人一看就容易废寝忘食的好东东,推荐早上睡眼朦胧的时候或者吃完午饭仔细研究,否则你会忘记吃饭和睡觉的!







