多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2
您當前位置:首頁 > php開源 > php教程 > 優化PHP代碼的四十三條建議(推薦)

優化PHP代碼的四十三條建議(推薦)

來源:程序員人生   發布時間:2014-06-03 22:11:44 閱讀次數:3256次

  1. If a method can be static, declare it static. Speed improvement is by a factor of 4. 如果一個方法可靜態化,就對它做靜態聲明。速率可提升至4倍。

  2. echo is faster than print. echo 比 print 快。

  3. Use echo’s multiple parameters instead of string concatenation. 使用echo的多重參數(譯注:指用逗號而不是句點)代替字符串連接。

  4. Set the maxvalue for your for-loops before and not in the loop. 在執行for循環之前確定最大循環數,不要每循環一次都計算最大值。

  5. Unset your variables to free memory, especially large arrays. 注銷那些不用的變量尤其是大數組,以便釋放內存。

  6. Avoid magic like __get, __set, __autoload 盡量避免使用__get,__set,__autoload。

  7. require_once() is expensive require_once()代價昂貴。

  8. Use full paths in includes and requires, less time spent on resolving the OS paths. 在包含文件時使用完整路徑,解析操作系統路徑所需的時間會更少。

  9. If you need to find out the time when the script started executing, $_SERVER[’REQUEST_TIME’] is preferred to time() 如果你想知道腳本開始執行(譯注:即服務器端收到客戶端請求)的時刻,使用$_SERVER[‘REQUEST_TIME’]要好于time()。

  10. See if you can use strncasecmp, strpbrk and stripos instead of regex. 檢查是否能用strncasecmp,strpbrk,stripos函數代替正則表達式完成相同功能。

  11. str_replace is faster than preg_replace, but strtr is faster than str_replace by a factor of 4. str_replace函數比preg_replace函數快,但strtr函數的效率是str_replace函數的四倍。

  12. 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. 如果一個字符串替換函數,可接受數組或字符作為參數,并且參數長度不太長,那么可以考慮額外寫一段替換代碼,使得每次傳遞參數是一個字符,而不是只寫一行代碼接受數組作為查詢和替換的參數。

  13. It’s better to use select statements than multi if, else if, statements. 使用選擇分支語句(譯注:即switch case)好于使用多個if,else if語句。

  14. Error suppression with @ is very slow. 用@屏蔽錯誤消息的做法非常低效。

  15. Turn on apache’s mod_deflate 打開apache的mod_deflate模塊。

  16. Close your database connections when you’re done with them. 數據庫連接當使用完畢時應關掉。

  17. $row[’id’] is 7 times faster than $row[id]. $row[‘id’]的效率是$row[id]的7倍。

  18. Error messages are expensive. 錯誤消息代價昂貴。

  19. Do not use functions inside of for loop, such as for ($x=0; $x < count($array); $x) The count() function gets called each time. 盡量不要在for循環中使用函數,比如for ($x=0; $x < count($array); $x)每循環一次都會調用count()函數。

生活不易,碼農辛苦
如果您覺得本網站對您的學習有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關閉
程序員人生
主站蜘蛛池模板: 欧美视频三级 | 国产欧美成人免费观看视频 | 色午夜影院| 欧美aa一级片 | 真人毛片免费全部播放完整 | 毛片传媒| 日本一级不卡一二三区免费 | 一区二区3区免费视频 | 一区二区3区免费视频 | 看黄色网址 | 国产2区| 精品久久久久久中文字幕无碍 | 男人懂得成a人v网站 | 欧美日韩精品一区二区三区视频在线 | 一本大道香蕉中文日本不卡高清二区 | xxxxx性欧美hd另类 | 欧美特黄一级aa毛片 | 老司机午夜精品视频观看 | 在线看片777av免费观看 | 黑人巨大粗xxxxxx | 嫩草影院久久精品 | 免费的看黄网站 | 久久爱伊人 | 精品毛片 | 中文字幕a∨在线乱码免费看 | 三级黄在线| 欧美free性| 国产图片亚洲精品一区 | 成人网在线视频 | 国产一级特黄aaaa大片野外 | 亚洲欧美日韩中文字幕久久 | 香蕉高清免费永久在线视频 | 久久成人免费 | 国产精品一国产精品 | 亚洲区中文字幕 | 国产日产欧产精品精品推荐小说 | 嫩草影院精品视频在线观看 | 亚洲综合一区二区三区四区 | 性色生活免费看性大片 | 大色虫成人午夜在线观看 | 亚洲无吗在线视频 |