.::: 一路问情 :::.
  • 注册
  • 登录
  • 会员
  • FTP资源中心
  • 七海争霸
  • 社区设施
  • 帮助
.::: 一路问情 :::. » 『建站技术』 » 优化动态网页技术PHP程序的12条技巧
‹‹ 上一主题 | 下一主题 ››
发新话题
  • 发新话题
  • 发布投票
  • 发布商品
  • 发布悬赏
  • 发布活动
  • 发布辩论
  • 发布视频
打印

[经验] 优化动态网页技术PHP程序的12条技巧

ivanisme
看贴不回的后果

初级会员

帖子
83 
威望
30 点 
金钱
201 元 
好评
0 点 
  • 个人空间
  • 发短消息
  • 加为好友
  • 当前离线
1楼 大 中 小 发表于 2008-2-26 09:32  只看该作者

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

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?这可能是保证把最经常访问的页面缓存起来的最快的方法了。



QQ
UID
73836 
精华
0 
积分
30 
钻石
0 克拉 
宣传
0 点 
来路
搜索引擎 
阅读权限
10 
来自
上海 
在线时间
0 小时 
注册时间
2008-2-25 
最后登录
2008-2-26 

查看详细资料

TOP

‹‹ 上一主题 | 下一主题 ››
发新话题
 

 

当前时区 GMT+8, 现在时间是 2008-7-7 05:39 蜀ICP备08000616号

清除 Cookies - 联系我们 - Ask Love - Archiver - WAP - TOP

Powered by Discuz! 6.0.0 []

Processed in 0.016904 second(s), 5 queries, Gzip enabled.

  • 控制面板首页
  • 编辑个人资料
  • 积分交易
  • 积分记录
  • 公众用户组
  • 个人空间管理
  • 资源中心
  • 名人堂
  • 社区银行
  • 醒目高亮
  • 勋章中心
  • 空间互踩
  • 便民查询
  • 邮箱图标
点击查看问情在alexa中的世界排名