当前位置: 首页 > 图文教程 > 网络编程 > PHP > PHP技巧:优化动态网页技术PHP程序的12条技巧

PHP
让我们来编写一些PHP实用的脚本
七种缓存使用武器 为网站应用和访问加速
动态网页PHP中引用&的使用注意事项
在PHP中全面阻止SQL注入式攻击
PHP自带可以代替echo调试的unit函数
小结:PHP动态网页程序优化及高效提速问题
php对特殊语句查询结果进行数组排序
实例:用PHP技术解决网站URL格式过长的问题
小结:PHP动态网页程序两个有用的小技巧
动态网页中直接不让访问PHP程序文件
网页实例:详细介绍用PHP来编写网页记数器
菜鸟学习:动态网页PHP基础学习笔记
利用Apache实现禁止图片盗链
PHP编程中常用的三则技巧
PHP制作的网站意见在线反馈表
大型Web需求解决方案 PHP定位突出
PHP实例:精确到每一秒钟的在线人数显示代码
实用:动态网页制作技术PHP的十个应用技巧
常见php页面漏洞分析及相关问题解决
PHP和MYSQL制作动态网站开发经验之谈

PHP技巧:优化动态网页技术PHP程序的12条技巧


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 49 ::
收藏到网摘: n/a

1、If a method can be static, declare it static. Speed improvement is by a factor of 4。

1、如果一个函数可以声明为静态的,那么就用静态的,速度是改进的一个因素4。


2、# Avoid magic like __get, __set, __autoload

2、避免使用__get, __set, __autoload等魔术函数


3、require_once() is expensive

3、require_once()是相当昂贵的。


4、Use full paths in includes and requires, less time spent on resolving the OS paths.

4、用include和require时,尽量用全路径,可以减少花在解决OS路径的时间


5、If you need to find out the time when the scrīpt started executing, $_SERVER[’REQUEST_TIME’] is preferred to time()

5、如果你需要知道一个脚本的开始运行时间,用 $_SERVER[’REQUEST_TIME’]比用time()要好


6、See if you can use strncasecmp, strpbrk and stripos instead of regex

6、如果可以用strncasecmp, strpbrk and stripos就别用正则


7、preg_replace is faster than str_replace, but strtr is faster than preg_replace by a factor of 4

7、preg_replace比str_replace要快,但是strtr比preg_replace更快


8、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 redundant replacement statements, passing one character at a time, instead of one line of code that accepts arrays as search and replace arguments.

一些函数,比如字符串替换函数,接受数组和单个字符做为参数,并且如果你的参数列表不是很长,考虑写一些冗余替换语句,每次传送一个字符,代替一行代码接受数组做为查找和替换的参数。


9、Error suppression with @ is very slow.

9、禁止错误输出符号@是非常慢的。


10、$row[’id’] is 7 times faster than $row[id]

10、、$row[’id’]比 $row[id]快7倍


11、Error messages are expensive

11、错误信息是非常昂贵的


12、Do not use functions inside of for loop, such as for ($x=0; $x < count($array); $x) The count() function gets called each time.

12、不要在循环内部使用函数,比如: for ($x=0; $x < count($array); $x)。count()函数在每次循环中都会被调用。


对于模板,你是否在用smarty?这可能是保证把最经常访问的页面缓存起来的最快的方法了。