(转载)优化PHP代码的40条建议
原文链接:http://webdev.csdn.net/page/58438f5e-704e-4e80-bdbd-7d06e8ecceb9#
40 Tips for optimizing your php Code
原文地址:http://reinholdweber.com/?p=3
英文版权归Reinhold Weber所有,中译文作者yangyang(aka davidkoree)。双语版可用于非商业传播,但须注明英文版作者、版权信息,以及中译文作者。翻译水平有限,请广大PHPer指正。
1. If a method can be static, declare it static. Speed improvement is by a factor of 4. 如果一个方法可静态化,就对它做静态声明。速率可提升至4倍。
2. echo is faster than print. echo 比 print 快。
3. Use echo’s multiple parameters instead of string concatenation. 使用echo的多重参数(译注:指用逗号而不是句点)代替字符串连接。
4. Set the maxvalue for your for-loops before and not in the loop. 在执行for循环之前确定最大循环数,不要每循环一次都计算最大值。
5. Unset your variables to free memory, especially large arrays. 注销那些不用的变量尤其是大数组,以便释放内存。
6. Avoid magic like __get, __set, __autoload 尽量避免使用__get,__set,__autoload。
7. require_once() is expensive require_once()代价昂贵。
8. Use full paths in includes and requires, less time spent on resolving the OS paths. 在包含文件时使用完整路径,解析操作系统路径所需的时间会更少。
9.
If you need to find out the time when the script started executing,
$_SERVER[’REQUEST_TIME’] is preferred to time()
如果你想知道脚本开始执行(译注:即服务器端收到客户端请求)的时刻,使用$_SERVER[‘REQUEST_TIME’]要好于time()。
10. See if you can use strncasecmp, strpbrk and stripos instead of regex. 检查是否能用strncasecmp,strpbrk,stripos函数代替正则表达式完成相同功能。
11.
str_replace is faster than preg_replace, but strtr is faster than
str_replace by a factor of 4.
str_replace函数比preg_replace函数快,但strtr函数的效率是str_replace函数的四倍。
12.
If the function, such as string replacement function, accepts both
arrays and single characters as arguments, and if your argument list is
not too long, consider writing a few redund
相关文档:
来源:蓝色理想 作者:Dreamer 2007年10月16日 14:50 网友评论:0条 点击:
2737
Dreamer的Blog:www.zhuoqun.net/
英文原文:Creating MyTube with Flex and PHP
原文地址:
http://www.onlamp.com/pub/a/php/2007/05/24/creating-mytube-with-flex-and-php.html
原文作者:Jack Herrington
随着宽带的普及、 ......
<?php
$conn = "what's the fucking";
?>
<mce:script type="text/javascript"><!--
var innn = "<?php echo $conn ?>";
document.write(innn);
// --></mce:script>
php和JavaScript的变量不能通用,但当我们需要在一个页面使用同一个变量时,可以 ......
转自:http://www.chinaz.com/news/Visit/091Y21R2009.html
Rasmus Lerdorf可能是格陵兰最著名的电脑牛人,他1995年创建了PHP脚本语言,并成功应用到他的网站中,在他的一手栽培下,PHP已变成一个强大的,完全成熟的语言,目前世界各地已有数百万PHP应用案例。
PHP创始人Rasmus Lerdorf
Linux Format杂志对Rasmus Lerd ......