« links for 2006-09-13 | 首页 | links for 2006-09-15 »

分类: 象步舞

2006年09月14日

Phorum作者Brian Moon的小贴士

  在刘昕推荐看的一篇Phorum项目创建者“月亮的脑袋瓜子”(呵呵,kidding,Brian Moon,布莱恩·摩恩,摩恩水龙头?呵呵,kidding again)采访录中Brian提到了他关于提高PHP代码执行效率的几点个人建议:

  1. Avoid classes. I am not saying never, just make sure you need a class before you make it. If it only has one or two methods that share no data, just use functions. Classes are faster now than ever in PHP, but a function still wins.
  2. Using " or ' does not matter for speed. Neither does breaking a string to insert a variable.
  3. This is gonna be a shock to some, but write your own code and don't use stuff like Smarty, PEAR and other PHP libraries. Its just faster to write the code you need to do what you need to do. All that weight will slow you down. The Phorum core does not rely on any 3rd party PHP code.
  4. Use EXPLAIN on every query you write. You won't, but if you strive to, you will be better for it.
  5. Its ok to use USE INDEX in your queries if it makes them faster. MySQL is good, but sometimes the human mind is better.
  6. Use temporary tables in MySQL and join with them when working with lots of data. Returning all that data to PHP is slow. The Phorum search is a good example of this. We only return the data you see on screen because we do all our sorting and filtering in temporary tables on the MySQL side. It was a huge perfomance gain.
  7. Lastly, benchmark stuff. Don't assume you know what is slow and what is fast. Phorum has a nice little set of timing functions in the distro you can use. If the difference is less than .001, forget about it.

  相信会编程的都应该看得懂英文,看不懂的也应该心有灵犀,所以就不翻译了,的确很受用:)

Posted by POPOEVER at 2006年09月14日 14:08 | back to top
Featured

Trackback Pings

本篇日志的回溯引用地址:

http://plod.popoever.com/acp630/mt-tb.cgi/1126

Comments


  1. #8419

    几乎所有的大PHP项目,都违反了上面的1和2,对于现在的机器来说,实质的问题还是数据存储吧。

    Posted by Kafeifei at 2006年09月15日 10:38 | back to top

  2. #8430

    关于 1,就好像,在理论上来说,所有 C++ 能做的事情,C 也是能做的。但是用 C++ 来做同样的事情,确实有很多理由。

    比如开发者的时间?那个恐怕比服务器的硬件还要更值钱。

    Posted by Livid at 2006年09月18日 14:38 | back to top

Post a comment

说老实话,做开心人,欢迎您留露箴言
即便如此,也请遵纪守法,勿放厥辞
汝国如汝母,辱国如辱母,吾辈当自强
您的观点仅代表个人,与本站无关,望请自尊

Thanks for signing in, . Now you can comment. (sign out)

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)


Remember me?