Home > Backend Development > PHP Tutorial > PHP开发几个提升性能的小技巧

PHP开发几个提升性能的小技巧

WBOY
Release: 2016-06-23 13:41:51
Original
1058 people have browsed it

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

echo "aaa"."bbb"

echo "aaa","bbb";


2.字符串包含变量时使用双引号

3.require要快于require_once

4.提前计算循环长度

<?php $items = array(1,2.3,4,5.6);$count = count($items);for($i=0;$i<$count;$i++){	$x = 123*$i;}
Copy after login


5.使用foreache循环代替while活for循环(执行速度: foreache

6.文件访问,使用file_get_contents()读取文件。PHP有四种从文件读取数据的方法:fread()、 file_get_contents()、file()和readfile()。fread()、file_get_contents()和readfile()以字符串的形式返回数据,file()将文件中的数据作为数组返回。只有file_get_contents()将文件缓存到内存中,以便更快的进行读写操作,这种方式称为内存映射。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template