让PHP跑得更快的6种方式

让PHP跑得更快的6种方式
提交 scriptviewer 87 days 以前


[文章原文来自http://blog.csdn.net]

以下的方式能够帮助PHP应用程序改善其扩展性。

1)目标代码缓存

每一次服务器的请求都需要PHP引擎编译并执目标代码。如果这一过程被缓存的话用户会获得更快的相应脚本。

在Internet上有许多目标代码的缓存解决方案(免费或者是商业产品):

A) Ioncube:http://www.ioncube.com

B) Zend Encoder:http://www.zend.com/products/zend_safeguard

C) Turckl MMCache: http://freshmeat.net/projects/turck-mmcache/

2)模板引擎

模板引擎提供了缓存的另一种方式。内容缓存。 模板引擎适合于您的页面有比较多的静态数据的情况。缓存系统还提供了代码与html的分离,使得将来的维护与更新更加容易。大多数的PHP模板引擎都是免费的。

A) Smarty Templates: http://smarty.php.net/

B) Pear Templates: http://pear.php.net/package/html_template_it/redirected

C) PHP savant: http://phpsavant.com/yawiki/

3)分布式对象缓存系统

这一类型最广泛使用的系统是memcached(http://www.danga.com/memcached/)

这一类型的系统将大量的数据库数据缓存在一个内存池中。

他们网站有趣的一段摘录:

“Danga Interactive developed memcached to enhance the speed of LiveJournal.com, a site which was already doing 20 million+ dynamic page views per day for 1 million users with a bunch of webservers and a bunch of database servers. memcached dropped the database load to almost nothing, yielding faster page load times for users, better resource utilization, and faster access to the databases on a memcache miss.”

5)输出压缩

今天几乎所有的浏览器都支持一种叫做gzip压缩的东西。Gzip能够减少你的整体输出到80%,但代价是:处理器的资源消耗会增加10%。使用这一压缩类型的好处是不仅能够减少你的带宽,而且页面也会更快速的加载。

在PHP启用(在php.ini增加以下几行):

zlib.output_compression = On
zlib.output_compression_level = (level) (where level is 1-9. Youy may want to try different values to see what is best for your system).

如果你使用的是Apache,你可以启用mod_gzip模块.

6)其它有用的东西

当使用数据库时,只取出你实际需要的数据。这听起来很理所当然,但是我碰到项目的程序员经常使用(select * from mytable)而实际上他们可以使用(select fieldIneed from mytable)。

如果可能的话为数据库表建立索引

了解更多可以看这里:

An interesting blog article I found mentions many interesting tricks that can be used: http://ilia.ws/archives/12-PHP-Optimization-Tricks.html

an article on zend.com about measuring performance: http://www.zend.com/zend/trick/trick-optimizing-php.php

原文地址:http://www.whenpenguinsattack.com/2006/08/14/using-php-in-large-websites-redone/?artid=134
原文地址:https://www.cnblogs.com/huqingyu/p/679195.html