PHP技巧:優(yōu)化動(dòng)態(tài)網(wǎng)頁技術(shù)PHP程序的12條技巧_PHP教程
推薦:PHP技巧:通過實(shí)例深入剖析require和include的用法在php中,include和require的作用比較容易混淆。下面我以一個(gè)經(jīng)典例子來深刻說明它們的區(qū)別。 當(dāng)我們經(jīng)常訪問一個(gè)數(shù)據(jù)庫時(shí),可以把連庫語句寫成一個(gè)文件
1、If a method can be static, declare it static. Speed improvement is by a factor of 4。
1、如果一個(gè)函數(shù)可以聲明為靜態(tài)的,那么就用靜態(tài)的,速度是改進(jìn)的一個(gè)因素4。
2、# Avoid magic like __get, __set, __autoload
2、避免使用__get, __set, __autoload等魔術(shù)函數(shù)
3、require_once() is expensive
3、require_once()是相當(dāng)昂貴的。
4、Use full paths in includes and requires, less time spent on resolving the OS paths.
4、用include和require時(shí),盡量用全路徑,可以減少花在解決OS路徑的時(shí)間
5、If you need to find out the time when the scrīpt started executing, $_SERVER[’REQUEST_TIME’] is preferred to time()
5、如果你需要知道一個(gè)腳本的開始運(yùn)行時(shí)間,用 $_SERVER[’REQUEST_TIME’]比用time()要好
6、See if you can use strncasecmp, strpbrk and stripos instead of regex
6、如果可以用strncasecmp, strpbrk and stripos就別用正則
7、preg_replace is faster than str_replace, but strtr is faster than preg_replace by a factor of 4
7、preg_replace比str_replace要快,但是strtr比preg_replace更快
8、If the function, such as string replacement function, accepts both arrays and single characters as arguments, and if your argument list is not too long, consider writing a few redundant replacement statements, passing one character at a time, instead of one line of code that accepts arrays as search and replace arguments.
一些函數(shù),比如字符串替換函數(shù),接受數(shù)組和單個(gè)字符做為參數(shù),并且如果你的參數(shù)列表不是很長(zhǎng),考慮寫一些冗余替換語句,每次傳送一個(gè)字符,代替一行代碼接受數(shù)組做為查找和替換的參數(shù)。
9、Error suppression with @ is very slow.
9、禁止錯(cuò)誤輸出符號(hào)@是非常慢的。
10、$row[’id’] is 7 times faster than $row[id]
10、、$row[’id’]比 $row[id]快7倍
11、Error messages are expensive
11、錯(cuò)誤信息是非常昂貴的
12、Do not use functions inside of for loop, such as for ($x=0; $x < count($array); $x) The count() function gets called each time.
12、不要在循環(huán)內(nèi)部使用函數(shù),比如: for ($x=0; $x < count($array); $x)。count()函數(shù)在每次循環(huán)中都會(huì)被調(diào)用。
對(duì)于模板,你是否在用smarty?這可能是保證把最經(jīng)常訪問的頁面緩存起來的最快的方法了。
分享:PHP技巧:分析利用PHP制作新聞系統(tǒng)的步驟我們可以用新聞系統(tǒng)來存儲(chǔ)新聞,我們可以對(duì)新聞進(jìn)行添加、刪除等操作,這樣減少了大家的工作量,為什么不實(shí)驗(yàn)一下。 首先,建立一個(gè)表。 以下為引用的
- PHPNOW安裝Memcached擴(kuò)展方法詳解
- php記錄頁面代碼執(zhí)行時(shí)間
- PHP中獎(jiǎng)概率的抽獎(jiǎng)算法程序代碼
- apache設(shè)置靜態(tài)文件緩存方法介紹
- php對(duì)圖像的各種處理函數(shù)代碼小結(jié)
- PHP 關(guān)于訪問控制的和運(yùn)算符優(yōu)先級(jí)介紹
- 關(guān)于PHP語言構(gòu)造器介紹
- php/js獲取客戶端mac地址的實(shí)現(xiàn)代碼
- php5.5新數(shù)組函數(shù)array_column使用
- PHP preg_match的匹配多國(guó)語言的技巧
- php 中序列化和json使用介紹
- php采集文章中的圖片獲取替換到本地
- 相關(guān)鏈接:
復(fù)制本頁鏈接| 搜索PHP技巧:優(yōu)化動(dòng)態(tài)網(wǎng)頁技術(shù)PHP程序的12條技巧
- 教程說明:
PHP教程-PHP技巧:優(yōu)化動(dòng)態(tài)網(wǎng)頁技術(shù)PHP程序的12條技巧。