PHP development experience-php Tutorial

Source: Internet
Author: User
PHP development experience 1. solid basic PHP knowledge, functions, constants, etc. try to use built-in methods to solve the problem (because personal writing is often less efficient than built-in methods );

II. implement as few functions as possible (because PHP is actually executed to process our code into the underlying language for machine execution. if there are many codes, the converted content is naturally time-consuming );

3. during optimization, you can test your own code through the stress test AB. after the code is optimized, stress test the efficiency again;


4. use less @ characters;

5. use the unset () function to unregister and release the variable;

6. less regular expressions, a double-edged sword;

7. avoid repeating in the for loop condition;

8. the key value of the array must be a string with quotation marks as the key value. why?

When $ arr = array ("key" => "hehe"); $ arr ["key"] is correct and improves efficiency

$ Arr [key] is not enclosed in quotation marks, because keys are not enclosed in quotation marks during PHP execution.

At this time, he will check whether the key is a constant. if the error mechanism is enabled, the system will prompt notice.

No key is found. If quotation marks are added, PHP will directly enter the $ arr array to find the key value as the key,

Relatively efficient

9. external factors affecting PHP performance include:


The inspiration from this is that when a website is slow, it may not be because of slow PHP performance, network problems, or hardware problems; as an architect, the problem cannot be solved by program optimization!

10. reading memory content is less efficient than reading database content. Therefore, websites with high traffic speed often cache data to the memory using distributed caches such as memcache and redis, then, read data with the memory;


11. XHPorf (derived from Facebook to test the PHP performance analysis tool) can be used to test the process of visiting websites, and can be quickly found in the red area of the process icon, which is time-consuming, optimize the method;


Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.