PHP代码优化 [英] PHP code optimization

查看:64
本文介绍了PHP代码优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道优化PHP代码的最佳方法是什么.有什么方法可以压缩PHP文件,或者可以删除所有空白以提高性能.除了编写函数的方式之外,还有什么方法可以提高PHP文件的性能?

I am just wondering what the best way to optimize PHP code is. Is there any way to compress PHP files, or would removing all of the white space improve performance. Any ways to improve performance in PHP files besides just the way you are writing functions?

推荐答案

如果在Apache上运行,则可以使用 eAccelerator ,它将缓存由PHP解析器生成的经过编译和优化的字节码,从而在第一次命中每个脚本后有效地删除了解析步骤.在我的博客的Wordpress安装中,每个页面的加载时间 (!)减少了一半.

If you are running on Apache, you can use eAccelerator, which will cache the compiled and optimized bytecode produced by the PHP parser, effectively removing the parsing step after the first hit to each script. On my blog's Wordpress install, this halves (!) the loading time of each page.

如果您要优化脚本的实际运行时间,则必须遵循标准的原则:配置您的脚本代码,找到瓶颈,以某种方式对其进行优化,然后重复执行直到脚本达到所需的速度为止.

If you are trying to optimize the actual running time of your script, you will have to follow the standard wisdom: profile your code, find the bottlenecks, optimize them somehow, and repeat until the script is as fast as you need it to be.

这篇关于PHP代码优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆