(תÔØ)ÓÅ»¯PHP´úÂëµÄ40Ìõ½¨Òé
ÔÎÄÁ´½Ó£ºhttp://webdev.csdn.net/page/58438f5e-704e-4e80-bdbd-7d06e8ecceb9#
40 Tips for optimizing your php Code
ÔÎĵØÖ·£ºhttp://reinholdweber.com/?p=3
Ó¢ÎÄ°æȨ¹éReinhold WeberËùÓУ¬ÖÐÒëÎÄ×÷Õßyangyang£¨aka davidkoree£©¡£Ë«Óï°æ¿ÉÓÃÓÚ·ÇÉÌÒµ´«²¥£¬µ«Ðë×¢Ã÷Ó¢ÎÄ°æ×÷Õß¡¢°æȨÐÅÏ¢£¬ÒÔ¼°ÖÐÒëÎÄ×÷Õß¡£·ÒëˮƽÓÐÏÞ£¬Çë¹ã´óPHPerÖ¸Õý¡£
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 redund
Ïà¹ØÎĵµ£º
Ò»°ãÇé¿öÏ£¬ÔÚ¿ª·¢»·¾³ÖзÃÎÊÒ»¸ö¾ßÌåÉÌÆ·µÄURLÊÇÕâÑùµÄ£º
http://localhost/phptest/show.php?id=1
µ«ÊÇÎÒÐèÒª¸ü¸ÄÒ»ÏÂURL£¬¶ÔËÑË÷ÒýÇæ¸üÓѺã¬È磺
http://localhost/phptest/1.html
ÕâÖ»ÊǾÙÀý°ÕÁË¡£
ÏÂÃæÎÒÃÇÀ´¿´¿´£¬ÕâÁ½ÌìÁ´½Ó×îºó´ïµ½µÄЧ¹ûÊÇÒ»ÑùµÄ£¬Çë×¢Òâä¯ÀÀÆ÷µØÖ·£¡
1¡¢Õý³£·ÃÎÊ£º
2¡¢Î±¾²Ì¬ºó£º
½ÓÏÂÀ ......
If you want to put some big table in the pdf file, you may got the layout messy. One way to solve the problem is to change the paper size. In "includes/cpdf_adapter.cls.php", Change the size you used in the array to whatever you want.
One tip: Replace Url into Clickable link.
$tex ......
ÓÉÓÚ ÔÚphp4µÄ»·¾³ÏÂ. ¶¼Ã»ÕÒµ½×Ô¶¯Éú³ÉµÄº¯Êý. ËùÒÔ×Ô¼º¸ÄдÁËÒ»¸ö±ðÈËЩµÄÀà. ÓÃÀ´×Ô¶¯Éú³Éxml Îļþ.
<?php
/*
*** ¹¦ÄÜ : php4×Ô動Éú³Éxml Îļþ類
*** @ edit: zxwo0o
*** @ time: 2009-9-22
*/
class php4xml{
var $version; //°æ±¾號
var $start; ......
PHPChina×ÊѶ£ºSmartyÊÇÓÉMonte OhrtºÍAndrei Zmievskiд³öµÄPHPÄ£°åÒýÇæ¡£Ëü²»Í¬ÓÚÆäËûµÄÄ£°åÒýÇ棬±ÈÈçFastTemplate»òÕßpatTemplate£¬ÆäÖÐÖ÷ÒªÔÒò¾ÍÊÇSmarty»á½«Ä£°åת»¯³ÉPHP½Å±¾£¬²¢ÌÞ³ýÿ´ÎʹÓøÃÄ£°åʱ¶¼»á³öÏÖÔÚ½âÎö»·½ÚÀïµÄÓÃÀ´¿ØÖƺʹíÎó¼ìÑéµÄ¸½¼ÓÂë¡£Õâ¸ö¹¦ÄÜʹSmartyÔÚ´óÐÍÓ¦Óú͸ßÁ÷Á¿ÍøÕ¾ÉÏÓÐÓÅÒìµÄ±íÏÖ¡£
......
̸µ½ÍøÒ³ËÑË÷ÒýÇæʱ£¬´ó¶àÊýÈ˶¼»áÏëµ½ÑÅ»¢¡£µÄÈ·£¬ÑÅ»¢¿ª´´ÁËÒ»¸ö»¥ÁªÍøÂçµÄËÑË÷ʱ´ú¡£È»¶ø£¬ÑÅ»¢Ä¿Ç°ÓÃÓÚËÑË÷ÍøÒ³µÄ¼¼ÊõÈ´²¢·Ç¸Ã¹«Ë¾ÔÏÈ×Ô¼º¿ª·¢µÄ¡£2000Äê8Ô£¬ÑÅ»¢²ÉÓÃÁËGoogle£¨www.google.com£©Õâ¼ÒÓÉ˹̹¸£´óѧѧÉú´´½¨µÄ·çÏÕ¹«Ë¾µÄ¼¼Êõ¡£ÀíÓɷdz£¼òµ¥£¬GoogleµÄËÑË÷ÒýÇæ±ÈÑÅ»¢ÏÈǰʹÓÃµÄ ......