Ec (2); Summarize some strategies for optimizing php program efficiency: 1. 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! Note the PHP version of file_get_contents when opening a URL file. 2. perform as few file operations as possible, although PHP file operations are not efficient; 3. script ec (2); script
Summarize some php program efficiency optimization strategies:
1. When file_get_contents can be used to replace file, fopen, feof, fgets, and other methods, try to use file_get_contents, because its efficiency is much higher! Note the PHP version of file_get_contents when opening a URL file;
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 );
4. Try to use PHP internal functions as much as possible (but in order to find a function that does not exist in PHP, it is a waste of time to write a user-defined function, experience problems !);
5. Do not declare variables inside the loop, especially big variables: Objects (doesn't it seem to be a concern in PHP ?);
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;
I have encountered problems related to the above policies in practice. Using these policies has greatly improved the efficiency. Try it ....
The following is an article about improving PHP efficiency:
========================================================== ========================================================== ===
Squeeze php to improve efficiency
Address: http://www.111cn.net/bbs/thread-13409-1-1.html
This essay is translated from various documents on the network (see the last reference), especially the speeches delivered by Ilia Alshanetsky at multiple php conferences, it mainly involves various techniques to improve php performance. For accuracy, many sections have detailed efficiency data and corresponding versions. If you are lazy, the data will not be given one by one and you can draw a conclusion directly. If you need to read the original document, please refer to the "references" section at the end of the article. The orange title is the recommendation part.
========================================================== ======================
Static call Members must be defined as static (PHP5 ONLY)
Tip: PHP 5 introduces the concept of static members, which is used in the same way as the static variables in php 4 functions, but the former is used as a member of the class. Static variables are similar to class variable in Ruby. All class instances share the same static variables.
QUOTE:
// Php CODE Highliting for CU by dZ902
Class foo {
Function bar (){
Echo ''foobar '';
}
}
$ Foo = new foo;
// Instance way
$ Foo-
<