Summary of php optimization and efficient speed-up. 1. using return in a function to pass an array is more efficient than using global, for example: functionuserloginfo ($ usertemp) {$ detailexplode (|, $ usertemp); return $ detail ;} $ loginuserl 1. in a function, it is more efficient to use return when passing an array than to use global. for example:
Function userloginfo ($ usertemp ){
$ Detail = explode ("|", $ usertemp );
Return $ detail;
}
$ Login = userloginfo ($ userdb );
Ratio
Function userloginfo ($ usertemp ){
Global $ detail;
$ Detail = explode ("|", $ usertemp );
}
Userloginfo ($ userdb );
Efficient
II. (this code is used to obtain the URL corresponding to the program directory, which is recommended)
$ Urlarray = explode ('/', $ HTTP_SERVER_VARS ['request _ URI ']);
$ Urlcount = count ($ urlarray); unset ($ urlarray [$ urlcount-1]);
$ Ofstarurl = 'http: // '. $ HTTP_SERVER_VARS ['http _ host']. implode ('/', $ urlarray );
Code comparison
$ Pre_urlarray = explode ('/', $ HTTP_SERVER_VARS ['http _ referer']);
$ Pre_url = array_pop ($ pre_urlarray );
Efficient
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 whether to use if (empty ($ a) whenever possible, because the program runs 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
11. usage
If ($ online ){
$ Online1 = $ online;
Setcookie ('online1', $ online, $ cookietime, $ ckpath, $ ckdomain, $ secure );
}
COOKIE will take effect immediately
Use
If ($ online)
Using return in functions is more efficient than using global when passing arrays, for example: function userloginfo ($ usertemp) {$ detail = explode (|, $ usertemp ); return $ detail;} $ login = userl...