PHP functions, files, and SQL statement optimization methods

Source: Internet
Author: User
When file_get_contents can be used to replace file, fopen, feof, fgets, and other methods, use file_get_contents as much as possible because of its high efficiency! But pay attention to file_ge... when file_get_contents can be used to replace file, fopen, feof, fgets, and other methods, try to use file_get_contents, because it is much more efficient! But pay attention to the php version of file_get_contents when opening a url file.

 

The file_get_contents () function reads the entire file into a string. like file (), the difference is that file_get_contents () reads the file into a string.

The file_get_contents () function is the preferred method for reading the file content into a string. if the operating system supports this function, the memory ing technology is used to improve the performance.

Syntax

File_get_contents (path, include_path, context, start, max_length) parameter description

Path is required, specifying the file to be read.

Include_path is optional. if you want to search for files in include_path, you can set this parameter to "1 ".

Context is optional. Specifies the file handle environment.

Context is a set of options that can modify the behavior of a stream. If null is used, it is ignored.

Start is optional. Specifies the location where the file starts reading. this parameter is newly added in php 5.1.

Max_length is optional. Specifies the number of bytes to read. this parameter is newly added to php 5.1.

Description

2. perform as few file operations as possible, although php file operations are not efficient;

3. optimize select SQL statements and perform insert and update operations as little as possible (I have been maliciously approved in update );

You can use lock table and unlock to insert instances in batches.

4. try to use php internal functions as much as possible (however, in order to find a function that does not exist in php, it is a waste of time and experience to write a user-defined function );

Internal functions such as time, date, fopen, rsort, etc.

5. do not declare variables inside the loop, especially big variables: objects (doesn't it seem to be a concern in php ?);

If for ($ I = 1; $ I <= 10; $ I ++) {$ a = 1 ;...}

6. do not use nested values for multi-dimensional arrays;

7. do not use regular expressions when you can use php internal strings to operate functions;

8. foreach is more efficient. use foreach instead of the while and for loops;

9. use single quotes instead of double quotes to reference strings;

10. "replace I = I + 1 with I + = 1. In line with the c/c ++ habits, high efficiency ";

11. unset () should be used up for global variables;

Address:

Reprinted at will, but please attach the article address :-)

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.