PHP ã³ã¼ãæé©å Best Practices 63+
ã¿ãããªã¿ã¤ãã«ã®è¨äºã Digg çµç±ã§çºè¦ããã¼ãã·ã¼ã代ããã«ã¨æãè¶ è¨³ã*1
PHP æé©å ãã¹ããã©ã¯ãã£ã¹ï¼
- 01. static ã«ã§ããã¡ã½ãã㯠static ã¨ãã¦å®£è¨ããããï¼4åéãï¼
- 02. echo ã®æ¹ã print ããéãã
- 03. echo 'æ','å'; ï¼ã«ã³ãåºåãï¼ã®æ¹ãã'æ'.'å' ï¼ãããé£çµï¼ããéãã
- 04. ã«ã¼ãã®æ大å¤ã¯ãã«ã¼ããå ãã§ã¯ãªããåãã«ã»ãããã¦ãããã
- 05. 大ããé åã®ãããªå¤æ°ã¯ unset() ãã¦ã¡ã¢ãªã解æ¾ãããã
- 06. ãã¸ãã¯ã¡ã½ããï¼ä¾ï¼ __get, __set, __autoloadï¼ã¯ä½¿ç¨ãé¿ãããã
- 07. require_once ã¯ãã¤ã³ã¹ããªã®ã§ãã
- 08. include ã require ã§ãã¡ã¤ã«ã¯ãã«ãã¹ã§æå®ãããã
- 09. ã¹ã¯ãªããéå§æé㯠time() ã§ãªã $_SERVER['REQUEST_TIME'] ã§åå¾ã
- 10. å¯è½ã§ããã°ãæ£è¦è¡¨ç¾ãã strncasecmpãstrpbrkãstripos ã使ããã
- 11. strtrï¼str_replace ã®4åéãï¼ ï¼ str_replace ï¼ preg_replace ã®é ã«éãã
- 12. å¼æ°ã«é åãæåå両æ¹ãåãå ¥ãããããªé¢æ°ã¯é¿ããåå¥ã«é¢æ°åãããã
- 13. if ããããã使ã£ã¦ããªã switch ãæ´»ç¨ããããï¼è¨³æ³¨ï¼ã£ã¦ãã¨ã§ããï¼ï¼
- 14. @ã«ããã¨ã©ã¼å¶å¾¡ã¯ããããé ãã
- 15. Apache ã® mod_deflateï¼Apache2ç³»ï¼ ã ON ã«ãã¦ããããï¼No.42 åç §ï¼
- 16. å¦çãçµãã£ãããã¼ã¿ãã¼ã¹ã®æ¥ç¶ã¯åã£ã¦ãããã
- 17. $row['id'] 㯠$row[id] ãã7åéãã
- 18. ã¨ã©ã¼ã¡ãã»ã¼ã¸ã¯ãã¤ã³ã¹ãã
- 19. for æã®æ¡ä»¶å¼ã«ã¯ count($array) ã®ãããªé¢æ°ããããªããï¼å¤æ°ã«æ ¼ç´ï¼
- 20. ã¡ã½ããå ã§ã¯ãã¼ã«ã«å¤æ°ãã¤ã³ã¯ãªã¡ã³ãããã®ãä¸çªéãã
- 21. ã°ãã¼ãã«å¤æ°ã®ã¤ã³ã¯ãªã¡ã³ãã¯ãã¼ã«ã«å¤æ°ãã2åé ãã
- 22. ãªãã¸ã§ã¯ãå¤æ°ï¼ä¾ï¼$this->v++ï¼ã®ã¤ã³ã¯ãªã¡ã³ãã¯ãã¼ã«ã«ãã3åé ãã
- 23. æªå®ç¾©ã®ãã¼ã«ã«å¤æ°ã®ã¤ã³ã¯ãªã¡ã³ãã¯å®ç¾©ããããã®ãã9ã10åé ãã
- 24. æªå®ç¾©ã®ã°ãã¼ãã«å¤æ°ã«ã¤ãã¦ãåæ§ã
- 25. ã¡ã½ããã®èµ·åã³ã¹ãã¯ã¯ã©ã¹å ã®ã¡ã½ããæ°ã¨ã¯ç¡é¢ä¿ã
- 26. æ´¾çã¯ã©ã¹å ã®ã¡ã½ããã¯ãåºåºã¯ã©ã¹ã§å®ç¾©ãããã¡ã½ãããããéãã
- 27. å¼æ°1ã¤ã®ç©ºé¢æ°ãå¼ã³åºãã®ã«ãããã¼ã«ã«å¤æ° $local++ 7ã8ååã®ã³ã¹ãã
- 28. ããã«ã¯ã©ã¼ã ãã ã·ã³ã°ã«ã¯ã©ã¼ã ã®æ¹ãè¥å¹²éãã
- 29. 03 ã¨éè¤ããï¼æ³¨ï¼ããã¯è¤æ°ã®å¼æ°ãåãåã echo ã§ã®ã¿æå¹ï¼
- 30. PHP ã¹ã¯ãªããã¯éç㪠HTML ãã¼ã¸ããã2ã10åã®æéããããã
- 31. ãã£ãã·ã¥ãå©ç¨ããããé常ãã³ã³ãã¤ã«åæ° x 25ã100ï¼ åéããªãã
- 32. ããããã£ãã·ã¥ã«ã¤ãã¦ãmemcached ã¨ã使ãããã
- 33. if (strlen($foo) < 5) ã調ã¹ãããªã if (!isset($foo{5})) ã¨æ¸ãã¨éãã
- 34. $i++ ãã ++$i ã®æ¹ãéããï¼ãããã opcode optimizer ãèµ°ã£ã¦ãå ´åï¼
- 35. å ¨é¨ãå ¨é¨ OOP ã§ãªãã¦ãè¯ããï¼ã³ã¹ããã¡ã¢ãªã®æµªè²»ã«ãªã£ã¦ãããï¼
- 36. ãã¹ã¦ã®ãã¼ã¿ãã¯ã©ã¹ã«ãããã¨ããªããã¨ãé åãåå便å©ã§ãã
- 37. ã¡ã½ãããåå²ããããªããï¼ã©ããåå©ç¨ããã®ãããèãããï¼
- 38. ã¡ã½ãããåå²ããããªã£ããå¾ã§ãããã§ãã§ããã
- 39. ãã¨ããç¨æããã¦ã é¢æ°ãã¡ ãæ´»ç¨ãããã
- 40. é常ã«æéã®ãããé¢æ° â Cè¨èªã«ããæ¡å¼µã¢ã¸ã¥ã¼ã«åãæ¤è¨ãããã
- 41. ã³ã¼ãããããã¡ã¤ãªã³ã°ãã¦ããã«ããã¯ãè¦ã¤ããããXdebug ã¨ãã
- 42. Apache ã® mod_gzipï¼Apache 1ç³»ï¼ã¯ã転ééãæ大80ï¼ æ¸ã
- 43. http://phplens.com/lens/php-book/optimizing-debugging-php.php ãè¦ã¦ãã
- 44. 28 ã¨éè¤ãã
- 45. 13 ã¨éè¤ãã
- 46. 19 ã¨éè¤ãã
- 47. ã«ã¼ãå¦çã«ã¯ foreach ã使ããã
- 48. è¤éãªã¯ã©ã¹ãä½ã£ã¦ããªãã¨æã£ãã â Singleton ã¢ãã«ãæ¤è¨ãããã*2
- 49. DB ã«å ¥ããå¤ãªã GET ãã POST ã使ãããï¼ããã©ã¼ãã³ã¹ãä¸ããï¼
- 50. å¯è½ãªãæ£è¦è¡¨ç¾ãããctype_alnumãctype_alphaãctype_digit ã使ããã
- 51. ãã¡ã¤ã«æå®ã¯ basename / file_exists / open_basedir ãããã«ãã¹æå®ãéãã
- 52. require_once ãã require ã使ãããï¼opcode ãã£ãã·ã¥ããã¿ã®çç±ã§ï¼
- 53. ä¸æçãªãã¡ã¤ã«ãä½ãã¨ãã«ã¯ tmpfile ã tempnam ã使ããã
- 54. å¤é¨ãµã¼ãã¹ã« XMLHTTP ã§æ¥ç¶ããã¨ãã«ã¯ã¨ã©ã¼åé¿ã®ãã Proxy ã使ããã
- 55. ãããã°ããã¨ã㯠error_reporting (E_ALL); ã«ãã¦ãããã
- 56. Apache ã® allowoverride ã "none" ã«ãã¦ããã¨ããã©ã¼ãã³ã¹ãåä¸ã
- 57. éçãªã³ã³ãã³ãã«ã¯ thttpd ã®ãããªé«éãªãã¡ã¤ã«ãµã¼ãã使ããã
- 58. ãã¹ãªã©ã®è¨å®ãã©ã¡ã¼ã¿ã¯é åã« serialize ãã¦å ¥ãããã£ãã·ã¥ãã¦ãããã
- 59. ã¢ã¯ã»ã¹ã®å¤ããã¼ã¸ã«ã¯ PHP ã® åºåãããã¡ãªã³ã° ã使ããã
- 60. DB åºæã® prepare ã¡ã½ããã§ã¯ãªã PDO::prepare ã使ããã
- 61. SELECT * ï¼ã¯ã¤ã«ãã«ã¼ãï¼ã使ãã®ã¯ããããã
- 62. PHP ããè³¢ã DB ãã¸ãã¯ï¼queries, joins, views, proceduresï¼ãæ´»ç¨ãããã
- 63. SQL ã®çç¥è¡¨è¨ãæ´»ç¨ãããã
ï¼ä¾ï¼INSERT INTO MYTABLE (FIELD1,FIELD2) VALUES (("x","y"),("p","q"));ï¼
以ä¸ã
ã£ã¦ãããããããã (ï¼Â´âï½)
åå㯠http://labs.unoh.net/2007/05/phptips.html ã¨åãã§ãããã
ãããã Tips ã¯æ¤è¨¼ç°å¢ã«ãã£ã¦ããããã¨å·®ãåºã¦ããã¿ããã§ããã©ã
ã©ã£ã¡ã«ããããè¿·ã£ãã¨ããªããã«ã¯åèã«ãã¦ãããããããªãããªã*3
å ãã¿ã®å ãã¿ããããã®ï¼å¼ç¨ã®å¼ç¨ã¨ãã§æ£ç¢ºã«ã¯ä¸æã§ããâ¦ï¼
- No.01ã43 http://reinholdweber.com/?p=3 (2007/10/14)
- No.44ã63 ALL ABOUT COFFEE, by William H. Ukers
- http://phplens.com/lens/php-book/optimizing-debugging-php.php (2005/02/28)
- PHP & Performance By: Ilia Alshanetsky (PDF)
- whenpenguinsattack.com - (2006/07/21)
- Optimizing PHP Through Habits - Joakim Nygård (2007/03/31)
ãããæ¸ãã¦ãéä¸ã«çºè¦ããé¢é£è¨äº
- http://labs.unoh.net/2007/05/phptips.htmlï¼æ¢åºã2007/05/13ï¼
- http://labs.unoh.net/2007/01/array_key_check.html (2007/01/16)
- http://labs.unoh.net/2006/10/php_4.html (2006/10/27)
- PHPプログラミングのベストプラクティス:phpspot開発日誌 (2007/08/20)
- 43. 基礎構文処理速度のあれこれ | 日経 xTECH(クロステック) (2007/07/04)
- Forget It Not: PHPの文字列連結のスピード (2006/08/26)
- http://www.mt312.com/php/41/ (2007/05/10)
ãªãã ããã¯ããã£ã¨ããããï¼
ã£ã¦æ¹ã¸ãç°¡åãªè§£èª¬ï¼ä¾ã¨ãï¼ã¤ãã¦ã¿ã¾ããããããããã°ã©ããã
â PHPコード最適化Tipsのウソと本当(解説) - カタコト日記
*1:æä¸ã®ãªã³ã¯ã¯ãå è¨äºã«ã¯ãªããã§ãããåèã®ããåæã«ã¤ãã¡ããã¾ããã
*2:åæï¼Do consider using the Singleton Method when creating complex PHP classes.
ã©ãããæå³ãªã®ãã¡ãã£ã¨ãããããã¾ããâ¦ãã³ã¡ã³ãæ¬ã§è©¦è¡é¯èª¤ãã¦ã¾ãã
*3:訳ãæãã£ããã¯ããã£ã¦ã ï¼ ä½ããæ ¹æ ãç¥ããã«ãããã使ãã®ã¯å±éºã ã¨æãã®ã§ãè±èªã§ããã©å ãã¿ããããã¦ã©ããã