Good writing standards improve the efficiency of PHP code execution "under"

Source: Internet
Author: User

Using single quotes instead of double quotation marks to contain strings can be faster. Because PHP will search for variables in a string surrounded by double quotes, single quotes will not, note: only echo can do this, it is a string can be used as a parameter of the "function" (in the PHP manual that Echo is a language structure, not a real function, so the function with double quotation marks).
28, try to do the cache, you can use memcached. The memcached is a high-performance memory object caching system that can be used to accelerate dynamic WEB applications and reduce database load. Caching of the OP code is useful so that the script does not have to recompile for each request. 29. When you manipulate a string and need to verify that its length satisfies a certain requirement, you will of course use the strlen () function. This function executes quite quickly because it does not do any calculations and only returns the length of the known string stored in the Zval structure (the built-in data structure of C for storing PHP variables). However, because strlen () is a function, it is somewhat slower, because function calls go through a number of steps, such as lowercase letters (lowercase, PHP does not differentiate between function names), and hash lookups, which follow the called functions. In some cases, you can use the isset () technique to speed up execution of your code. (example below) if (strlen ($foo) < 5) {echo "Foo is too Short";} (compare with the following tips) if (! Isset ($foo {5})) {echo "Foo is too Short";} call Isset () happens to be faster than strlen (), because unlike the latter, Isset () as a language structure, means that its Do not require function lookups and lowercase letters. In other words, you're actually not spending much overhead in the top-level code that examines the length of the string. 34. When the increment or decrement of the variable $i is executed, $i + + will be slower $i than + +. This difference is unique to PHP and does not apply to other languages, so please do not modify your C or Java code and expect them to become fast and useless. + + $i is faster because it requires only 3 instructions (opcodes), $i + + requires 4 instructions. The post increment actually produces a temporary variable, which is then incremented. The predecessor increment is incremented directly on the original value. This is one of the most optimized processing, as Zend's PHP optimizer did. It is a good idea to keep this optimization in mind, as not all of the instruction optimizer will do the same optimizations, and there are a large number of Internet service providers (ISPs) and servers that do not have the command optimizer installed. 35, not the object-oriented (OOP), object-oriented tends to be very expensive, each method and object calls will consume a lot of memory. 36, not to use the class to implement all the data structure, arrays are also useful. 37, do not subdivide the method too much, think carefully about what you really want to reuse what code? 38, when you need, you can always divide the codeJia Cheng method. 39, try to use a large number of PHP built-in functions. 40. If there are a lot of time-consuming functions in your code, you might consider implementing them in C extensions. 41. Evaluate the test (profile) of your code. The inspector will tell you what parts of the code are consuming time. The Xdebug debugger contains an inspection program that can show the bottleneck of the code in general. 42, Mod_zip can be used as Apache module, to compress your data instantly, and to reduce the data transfer volume by 80%. 43, in the case can be replaced with file_get_contents file, fopen, feof, Fgets and other series of methods, as far as possible with the file_get_contents, because his efficiency is much higher! But pay attention to file_get_contents in the open a URL file when the PHP version of the problem, 44, as little as possible to file operations, although PHP file operation efficiency is not low; 45, optimize the SELECT SQL statement, as far as possible under the circumstances as little as possible inse RT, update operation (on update, I was a bad batch); 46. Use PHP intrinsics as much as possible (but I'm trying to find a function that doesn't exist in PHP, wasting the time that could have written a custom function, experience problems!) 47. Do not declare variables in the loop, especially large variables: objects (this seems to be more than just a question in PHP?). ); 48, multi-dimensional array try not to loop nested assignment, 49, in the case of PHP internal string operation function, do not use regular expression, 50, foreach more efficient, try to use foreach instead of while and for Loop, 51, single quotation mark instead of double quotation mark reference string ; 52, "Replace I=i+1 with I+=1. In accordance with the habit of C + +, high efficiency "; 53, the global variable, should be used up unset () off. Free to receive the Lamp Brothers and original PHP tutorial CD/"Detailed PHP" Essentials Edition, details of the website customer service: Http://www.lampbrother.netPHPCMS two times development /index.php?u=5 Development of HTTP://YUN.ITXDL.CN/ONLINE/WEIXIN/INDEX.PHP?U=5 Mobile Internet server-side development Index.php?u=5javascript Course HTtp:// Training Camp Http://
  • 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: 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.