Php?? Optimization Chapter

Source: Internet
Author: User
PHP optimization is divided into three parts

1, encoding optimization

2,opcode Cache

3, variables and data caching

Coding section

1, the string connection is using "," instead of "." No.

echo "HI". " There "." Good ";

echo "HI", "there", "good";

?>

2, string contains variable when using double quotation marks instead of single quotation mark

$name = "PHP"

Echo ' Hi there is '. $name;

echo "Hi there, $name";

?>

3, prefer to use require instead of require_once

A large number of operation State (STAT) calls are made when the PHP script is imported, so 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, when iterating over the array, use foreach first, followed by the For and while


6, large file access is preferred using file_get_contents ().

7, in a defined class, you can use a public variable without using a method to manipulate a private variable, if it is not necessary.


OpCode cache

1,apc

2,xcache

3,eaccelerator

Variables and data caching

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.