Some tips for improving PHP performance

Source: Internet
Author: User


Since the advent of PHP with its good cross-platform, efficient development mechanism has a large share of the web domain. Because it is running the mechanism is the script interpretation after the execution of the relevant resources will be recycled, so PHP developers are very little concerned about his resource consumption caused performance problems, but I am a pursuit of the ultimate perfectionist, especially for performance, So summed up some of the PHP writing optimization plus sub-items hope to have this knowledge needs of the peer friends help.


1, $_server["Request_time"]: $_server["Request_time" is recorded in memory when the script executes, time () function is called Si cho from the kernel to obtain a timestamp, the difference is $_ server["Request_time"] is a script that will exist in memory every time it executes, if there is not a large sleep $_server["request_time" can be used instead of in memory.


2.Include_once is more time-consuming than include . Because it needs to check if the class you want to include is already included.

3, less use regular . Higher-level functionality consumes more resources, so if you can use string processing methods such as the STR_ series instead of regular, try to use the string processing method.


4, the reference file using absolute path ... /etc relative directory references will cause the script to find the corresponding resource from the current directory when invoking the related resource, which is not as obvious as pointing directly to the target.


5. use single quotes as much as possible for strings . Double-quoted strings are interpreted to find out if there are any variables in the string.


6, == = Faster than = =, of course, the range is greater than = =, so there will be a range of matching actions, which is somewhat similar to the scope of the database and the primary key lookup performance differences.

Author GJ

Some tips for improving PHP performance

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.