Summary: PHP dynamic web page program optimization and efficient acceleration title

Source: Internet
Author: User
Return is more efficient than global when an array is passed, for example: functionuserloginfo ($ usertemp) {$ detail = explode ("", $ usertemp); return $ detail ;} $ login = userloginfo ($ userdb); than functionuser

Return is more efficient than global when an array is passed, 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 and is recommended for applications)

$ 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. it is more efficient to determine the application of the constant value in the cycle.

$ A = 2; $ B = 2;

For example

If ($ a ==$ B) $ c = $;

Ratio

If ($ a ===$ B) $ c = $;

Efficient

4. when querying mysql, try to use where in with less limit

Limit queries the first few records of multiple records, which is fast, but the query speed is slow

Application in. the query of persistent records is very fast. the first running of non-persistent records will be a little slower, but it will be faster later!

V. NT Server data control is less stable than unix/linux

6. try to apply ob_start () to the application before output. it can accelerate the output speed and be used in NT or nuli/linux. for unlix servers, if ob_start ('OB _ gzhandler') is used '); higher output efficiency

7. apply if ($ a = his value) whenever possible during the determination and apply if (empty ($ a) whenever possible. as a result, the program runs faster.

8. application time not supported! = Equivalent to <> efficiency

9. Personal experience $ a = '000000'; efficiency is quite different from $ a = '000000 '.

10. Application of standardized SQL statements will facilitate MySQL parsing

11. Application

If ($ online ){

$ Online1 = $ online;

Setcookie ('online1', $ online, $ cookietime, $ ckpath, $ ckdomain, $ secure );

}

COOKIE will take effect immediately

Application

If ($ online)

Setcookie ('online1', $ online, $ cookietime, $ ckpath, $ ckdomain, $ secure );

The COOKIE needs to be refreshed again to take effect.

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.