7.1 when file_get_contents can be used to replace file, fopen, feof, fgets, and other methods, file_get_contents should be used as much as possible because of its high efficiency! Note the php Tutorial version when file_get_contents opens 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 (isn't it just a matter of attention in php ?);
6. Do not use nested values for multi-dimensional arrays;
7. Do not use regular expressions when using internal php 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. For global variables, unset () should be used up;
12. In for or foreach, replace $ temparray [] = $ field with $ temparray [count ($ temparray)] = $ field
13. 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:
Copy the code as follows:
// Php code highliting for cu by dz902
<? Php
Class foo {
Function bar (){
Echo 'foobar ';
}
}
$ Foo = new foo;
// Instance way
$ Foo-> bar ();
// Static way
Foo: bar ();
?>
Static calling uses non-static members, which is 50-60% slower than static calling. This is mainly because the former generates an e_strict warning and the internal switch is also required.
Use a class constant (php5 only)
Tip: php 5's new features are similar to c ++'s const.
The benefit of using a class constant is:
-No additional overhead for parsing during compilation
-The pooled tables are smaller, so internal search is faster.
-The class constant only exists in the specified "namespace", so the name of the miscellaneous is shorter.
-Code cleaner to make debugging easier
(Temporarily) do not use require/include_once
Require/include_once will open the target file every time it is called!
-If the absolute path is used, php 5.2/6.0 does not have this problem.
-The new apc cache system has solved this problem.
File I/o increase => efficiency reduction
If necessary, you can manually check whether the file has been require/include.
Do not call meaningless functions
Do not use functions when there are corresponding constants.
Quote:
Copy the code as follows:
// Php code highliting for cu by dz902
<? Php
Php_uname ('s ') = php_ OS;
Php_version () = php_version;
Php_sapi_name () = php_sapi;
?>