PHP优化小建议

1 、、 foreach 效率更高,尽量用 foreach 代替 while 和 for 循环

2 、、循环内部不要声明变量,尤其是对象这样的变量

3 、、在多重嵌套循环中,如有可能,应当将最长的循环放在内层,最短循环放在外层,从而减少 cpu 跨循环层的次数,优化程序性能

4 、、用单引号替代双引号引用字符串以实现 PHP 性能优化

5 、、用 i+=1 代替 i=i+1 。 符合 c/c++的习惯,效率还高

6 、优化 Select SQL 语句,在可能的情况下尽量少的进行 Insert 、 Update 操作,达到 PHP 性能优化的目的

7 、、尽量的少进行文件操作,虽然 PHP 的文件操作效率也不低的

8 、、尽可能的使用 PHP 内部函数

9 、、在可以用 PHP 内部字符串操作函数的情况下,不要用正则表达式

10 、 feof 、 fgets 、 fopen 、在可以用 file_get_contents 替代 file 、系列方法的情况下,尽量用 file_get_contents ,因为它的效率高得多。 但是要注意 file_get_contents 在打开一个 URL 文件时候的 PHP 版本问题

随机推荐

  1. Oracle/PLSQL: ORA-06550

    参考: http://blog.csdn.net/haiross/article/details/20612135 Oracle/PLSQL: ORA-06550 Learn the cause an ...

  2. CentOS7 安装Nginx

    由于需要,这段时间学一点“nginx”.关于nginx就不介绍了,http://wiki.nginx.org/Main有非常详细的介绍.安装等. 安装软件我习惯到官网下载源码,http://nginx ...

  3. [css]全屏背景图片设置,django加载图片路径

    <head><style type="text/css"> #bg { position:fixed; top:; left:; width:100%; h ...

  4. 解决mybatis foreach 错误: Parameter '__frch_item_0' not found

    解决mybatis foreach 错误: Parameter '__frch_item_0' not found 在遍历对象的属性(是ArrayList对象)时报错: org.mybatis.spr ...

  5. [No00009F]CMD在执行命令时的中断快捷键

    有两种: Ctrl+C:完全中断.类似于C语言在while循环中的Break: Ctrl+Break(Pause键):单步中断.类似于C语言在while循环中的Continue:

  6. webstorm对WebGL自动提示

    默认竟然没有勾选上,怪不得提示的时候,有很多webgl接口找不到方法(虽然可以运行).

  7. [LeetCode] Game of Life 生命游戏

    According to the Wikipedia's article: "The Game of Life, also known simply as Life, is a cellul ...

  8. [LeetCode] Longest Consecutive Sequence 求最长连续序列

    Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...

  9. [LeetCode] Roman to Integer 罗马数字转化成整数

    Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...

  10. 调用altera IP核的仿真流程—上

    调用altera IP核的仿真流程—上 在学习本节内容之后,请详细阅读<基于modelsim-SE的简单仿真流程>,因为本节是基于<基于modelsim-SE的简单仿真流程>的 ...