Php ?? Optimization

Source: Internet
Author: User
Php ?? Php optimization consists of three parts:

1. encoding optimization

2. Opcode cache

3. variable and data cache

Encoding part

1. the string connection uses "," instead ".".

Echo "hi". "there". "good ";

Echo "hi", "there", "good ";

?>

2. double quotation marks instead of single quotation marks are used when a string contains variables.

$ Name = "php"

Echo 'Hi there is '. $ name;

Echo "hi there, $ name ";

?>

3. use require first, instead of require_once.

When a php script is imported, a large number of operations (stat) are called. therefore, require is faster than required_once.

4. calculate the cycle length in advance

$ Items = array (1, 2, 3, 4, 5, 6, 7, 8, 9 );

For ($ I = 0; $ I < p> <>

{

Statment;

}

$ Items = array (1, 2, 3, 4, 5, 6, 7, 8, 9 );

$ Total = count (items );

For ($ I = 0; $ I <$ total; I ++)

{

Statment;

}

?>

5. foreach is preferred for loop access to arrays, followed by for and while


6. file_get_contents () is preferred for accessing large files ().

7. You can use public variables unless necessary in the defined class, rather than using methods to operate private variables.


Opcode cache

1, APC

2. XCache

3. eAccelerator

Variable and data cache

1, APC

2, memcached

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.