<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6648236360472666945</id><updated>2012-05-07T02:51:46.812+08:00</updated><category term='網路交易'/><category term='CardGame'/><category term='Program'/><category term='網路遊戲'/><category term='星海爭霸2'/><category term='PSP'/><category term='NDS 攻略'/><category term='料理筆記'/><category term='VB.NET'/><category term='Apple'/><category term='SFC'/><category term='摩爾莊園'/><category term='Ajax'/><category term='C++'/><category term='Chrome'/><category term='DnD'/><category term='NDS資訊'/><category term='Mac'/><category term='Software'/><category term='精靈幻境系列'/><category term='Writing'/><category term='RO OpenKore'/><category term='FC'/><category term='PS'/><category term='星海爭霸2地圖'/><category term='摩爾勇士'/><category term='Culdcept'/><category term='生活相關'/><category term='遊戲設計'/><category term='RO'/><category term='限時免費APP'/><category term='BioInfo'/><category term='MHP3'/><category term='博弈遊戲'/><category term='LoL'/><category term='星海爭霸2雜錦'/><category term='Music'/><category term='RO JA.NET'/><category term='3DS'/><category term='遊戲新聞'/><category term='軟體相關'/><category term='模擬器'/><category term='雜談錄'/><category term='Java'/><category term='iOS開發'/><category term='動畫專區'/><category term='特價折扣'/><category term='ROM'/><category term='Php'/><category term='WebGame'/><category term='JavaScript'/><category term='遊戲王'/><category term='Blog'/><category term='魔法風雲會'/><title type='text'>GameLifeX</title><subtitle type='html'>　不只是遊戲，是生活</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://gamelifex.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6648236360472666945/posts/default/-/Php'/><link rel='alternate' type='text/html' href='http://gamelifex.blogspot.com/search/label/Php'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Jason</name><uri>http://www.blogger.com/profile/00667801849417949181</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='http://2.bp.blogspot.com/_BsYyM_o2_Pc/S8A0d9jcmJI/AAAAAAAAAOA/jkCxsQg-hCM/S220/%E7%B4%AF.bmp'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6648236360472666945.post-2447079392400488301</id><published>2011-04-18T17:37:00.002+08:00</published><updated>2011-04-18T17:37:54.649+08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Php'/><title type='text'>[轉載][備份]40 個 PHP 效能調校的技巧</title><content type='html'>文章來源:&lt;a href="http://mikuru.tw/wordpress/archives/418"&gt;http://mikuru.tw/wordpress/archives/418&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;div style="background-color: transparent; color: #444444; font-family: 'Lucida Sans Unicode', Arial, sans-serif; font-size: 12px; line-height: 17px; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;最近在玩 Smarty &amp;amp; XAJAX&lt;br style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;無意間看到了&amp;nbsp;&lt;a href="http://reinholdweber.com/?p=3" style="background-color: transparent; color: #444444; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Reinhold Weber 寫了一些提昇 PHP 效能的討論&lt;/a&gt;&lt;/div&gt;&lt;div style="background-color: transparent; color: #444444; font-family: 'Lucida Sans Unicode', Arial, sans-serif; font-size: 12px; line-height: 17px; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;網路上雖有中國簡體字版本，但由於文化隔閡過大，翻譯無法達到 「信、達、雅」 的目標&lt;br style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;於是又根據原文將它翻譯成台灣正體中文，並加上自己的註解。&lt;br style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;&lt;span id="more-418" style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;ol style="background-color: transparent; color: #444444; font-family: 'Lucida Sans Unicode', Arial, sans-serif; font-size: 12px; line-height: 17px; margin-bottom: 15px; margin-left: 35px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;儘量以靜態宣告方法，這將比動態宣告快 4 倍。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;echo 比 print 快。(就顯示字串而言)&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;echo 的參數可用 「,」 (逗號) 銜接，這比用 「.」 (句號) 串接來得快。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;在 for 迴圈之前定好最大值，而不要在迴圈內計算。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;使用 unset 來釋放記憶體，特別是針對龐大陣列。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;避免使用 __get, __set, __autoload 等物件導向的 magic method。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;require_once() 的代價非常高。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;使用 include 與 require 時採用完整路徑，可以節省作業系統解析路徑的時間。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;要查詢腳本何時執行，$_SERVER[』REQUEST_TIME'] 比 time() 來得好。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;以 strncasecmp, strpbrk and stripos 代替正規表示式。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;str_replace 比 preg_replace (PCRE 的 replace) 快；strtr 則比 str_replace 又快了 4 倍。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;在某些函數可以接受陣列或單一字元為引數 (譬如：字串替換函數)。&lt;br style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;若您的引數並非很長，可考慮撰寫多個替換敘述；並建議一次傳入一個字元，而不要一口氣傳入整個陣列。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;處理流程控制時，使用 switch-case 比用多個 if-elseif 好。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;使用 「@」 抑制錯誤訊息會非常慢。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;開啟 apache 的 mod_deflate 支援。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;當不使用資料庫時，記得關閉連結。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;陣列中引數加上單引號將比不加快了 7 倍，如 $row[』id'] 與 $row[id]。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;顯示錯誤訊息的代價很高。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;別再迴圈中使用函數，它在每一圈都會被呼叫。如 for ($x=0; $x &amp;lt; count($array); $x) 的 count()。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;於方法中遞增本地變數是最快的，幾乎與函數中呼叫本地變數一樣快。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;遞增全域變數比遞增本地變數曼 2 倍。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;遞增一個物件的屬性 (如 $this-&amp;gt;prop++) 比本地變數慢 3 倍。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;遞增一個未定義的本地變數比預先賦值的還慢 9-10 倍。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;宣告了全域變數而沒在函數中使用它，仍然會降低執行速度。因為 PHP 仍會檢查函數內是否存在全域變數。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;方法調用 (method invocation) 與類別中定義的方法數量無關，作者於方法中增加了 10 個方法，前後之效能並無變化。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;衍生類別中的方法比基礎類別中的方法來得快。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;呼叫含有一個參數的空函數所費時間，相當於遞增本地函數的 7-8 倍；&lt;br style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;同樣的作法，對於類別的方法將要 15 倍。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;若字串內無變數需代換，可用單引號代替雙引號。這麼作此將省去變數掃瞄的時間。&lt;br style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;(如 『just a string' 而非 「just a string」)&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;當使用 echo，以逗號代替句號分隔字串。類似第三條所述，但此處將 echo 當成 statement 而非 function。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Apache 對 PHP 的解析比 HTML 慢了 2-10 倍，所以儘可能地使用靜態網頁。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;若無快取機制，PHP 腳本每次都會編譯一次。安裝快取相關機制將省去 25-100% 重新編譯的時間。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;儘可能地使用快取機制。比方說採用 memcached，他是一個高效能的記憶體物件快取系統，藉由降低資料庫負載來加速動態網頁應用。&lt;br style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;OP code 快取也很有用，它可以避免每次重複編譯腳本。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;當處理字串時，檢查字串的長度將會用到 strlen() 函數。此函數幾乎不需任何運算，它把資料結構中已知的字串長度直接傳回，故速度很快。&lt;br style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;(PHP 內部的 zval 資料結構，採用 C 語言 struct 來儲存變數)&lt;br style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;然而由於 strlen() 是函數，函數呼叫仍需耗費相當的運算時間；某些時候可利用 isset() 來改善執行速度。&lt;div style="background-color: transparent; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;/div&gt;&lt;div style="background-color: transparent; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;例如：&lt;br style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;&lt;code style="background-color: transparent; color: green; font-weight: normal; font: normal normal normal 1.1em/normal Consolas, 'Courier New', Courier, Fixed; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;if (strlen($foo) &amp;lt; 5) { echo "Foo is too short"; }&lt;/code&gt;&lt;br style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;與&lt;br style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;&lt;code style="background-color: transparent; color: green; font-weight: normal; font: normal normal normal 1.1em/normal Consolas, 'Courier New', Courier, Fixed; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;if (!isset($foo{5})) { echo "Foo is too short"; }&lt;/code&gt;&lt;/div&gt;&lt;div style="background-color: transparent; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;呼叫 isset() 比 strlen() 快是因為，isset() 是語言架構而非函數，故無須函數查詢與大小寫轉換。&lt;br style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;這表示決定字串長度幾乎不需要額外成本。&lt;/div&gt;&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;當遞增或遞減時，後置運算會比前置運算稍慢一點。 ($i++ 比 ++$i 慢)。&lt;br style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;這是 PHP 的特性，故別急著去更改您的 C 或 Java 程式碼，這不會讓它們加速。&lt;br style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;由於後置遞增/遞減會先建立一個暫存變數而後遞增，前置遞增/遞減則直接對原值操作。&lt;br style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;故 ++$i 僅使用 3 個 opcode, 而 $i++ 使用 4 個。&lt;br style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" /&gt;Zend 的 PHP optimizer 也採用此技巧作最佳化。&lt;div style="background-color: transparent; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;&lt;/div&gt;&lt;div style="background-color: transparent; margin-bottom: 10px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;請記得必非所有 optimizer 都會對 opcode 作最佳化，且多數 ISP 並不會對 opcode 作最佳化。&lt;/div&gt;&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;並非所有事情都要訴諸 OOP，方法與物件的成本很高，消耗大量的記憶體。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;陣列很好用，它讓您不需自行實做每個資料結構。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;不要過度的拆開方法 (method)，想清楚哪些程式碼是會被重新使用的。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;當需要時，可以把程式碼拆成方法。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;充分利用 PHP 提供的眾多函數。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;若您的程式碼有很耗時間的功能，儘量以 C 語言撰寫延伸套件 (extension)。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;對您的程式碼進行側寫 (profile)，側寫器將告訴您程式碼執行的時間。Xdebug 除錯器即含有側寫器，將告訴您整體表現的瓶頸在哪裡。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;Apache 提供的 mod_gzip 能即時壓縮資料，它省去 80% 的傳輸資料量。&lt;/li&gt;&lt;li style="background-color: transparent; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;讀讀看&amp;nbsp;&lt;a href="http://phplens.com/lens/php-book/optimizing-debugging-php.php" style="background-color: transparent; color: #444444; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;"&gt;John Lim 所撰寫有關 PHP 最佳化的文章&lt;/a&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6648236360472666945-2447079392400488301?l=gamelifex.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://gamelifex.blogspot.com/feeds/2447079392400488301/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://gamelifex.blogspot.com/2011/04/40-php.html#comment-form' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6648236360472666945/posts/default/2447079392400488301'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6648236360472666945/posts/default/2447079392400488301'/><link rel='alternate' type='text/html' href='http://gamelifex.blogspot.com/2011/04/40-php.html' title='[轉載][備份]40 個 PHP 效能調校的技巧'/><author><name>Jason</name><uri>http://www.blogger.com/profile/00667801849417949181</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='26' src='http://2.bp.blogspot.com/_BsYyM_o2_Pc/S8A0d9jcmJI/AAAAAAAAAOA/jkCxsQg-hCM/S220/%E7%B4%AF.bmp'/></author><thr:total>0</thr:total></entry></feed>
