php代码优化

来源:互联网 发布:linux locale命令i18n 编辑:程序博客网 时间:2024/05/17 02:44

一、测试工具:

Apache Benchmark (ab)

ab -c 10 -n 100000 localhost/index.php    //模拟10万个请求,5个并发


二、PHP代码优化

1,使用逗号而不是句点来连接字符串

       echo 'hello','hi';

2,字符串包含变量时使用双引号而不是单引号    

3,使用require 而不是requireonce

4,提前计算循环长度

5,使用foreach访问数组快于for 和 while 循环

6,file_get_contents()快于fread()

     file_get_contents()将文件缓存在内存之中,以便更快的进行读写操作,这种方式称为内存映射。


0 0
原创粉丝点击