PHP problem summary: Summary of PHP optimization and efficient Acceleration
Source: Internet
Author: User
PHP problem summary: Summary of PHP optimization and efficient acceleration-Linux Enterprise Application-Linux server application information. The following is a detailed description. 1. In a function, it is more efficient to use return when passing an array than to use global. For example:
3. When judging in a loop, it is more efficient to use constant to determine the value.
$ A = 2; $ B = 2;
For example
If ($ a ==$ B) $ c = $;
Ratio
If ($ a ===$ B) $ c = $;
Efficient
4. Use where in to use less limit for mysql queries
Limit queries the first few records of multiple records, which is fast, but the query speed is slow
Using in. the query of the continuity record is very fast. The first running of the non-continuity record will be a little slower, but it will be faster later!
V. NT server data operation stability is less than unix/linux
6. Use ob_start () whenever possible before output. It can accelerate the output speed. It is applicable to NT or nuli/linux. If ob_start ('ob _ gzhandler') is used for unlix servers '); higher output efficiency
7. Try to use if ($ a = his value) when determining if it is negative, because empty ($ a) is faster.
8. usage time! = Equivalent to <> Efficiency
9. The efficiency of using $ a = "11111111111111" in personal experience is quite different from that in $ a = '000000 '.
10. Using standard SQL statements will facilitate MySQL Parsing
13. truncation of string optimization functions (can be avoided? Characters)
Function substrs ($ content, $ length ){
If (strlen ($ content)> $ length ){
$ Num = 0;
For ($ I = 0; $ I <$ length-3; $ I ++ ){
If (ord ($ content [$ I])> 127) $ num ++;
}
$ Num % 2 = 1? $ Content = substr ($ content, 0, $ length-4): $ content = substr ($ content, 0, $ length-3 );
$ Content. = '...';
}
Return $ content;
}
For example, $ newarray [1] = substrs ($ newarray [1], 25 );
14. case-insensitive shielding in the program
For ($ asc = 65; $ asc <= 90; $ asc ++)
{// Strtolower () This function generates garbled characters on some servers!
If (strrpos ($ regname, chr ($ asc ))! = False)
{
$ Error = "to avoid user name confusion, uppercase letters are not allowed in the user name. Please Use lowercase letters ";
$ Reg_check = 0;
}
}
15. Do not use file (); or do not use fget (); (unstable or slow) take an Array Function
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service