PHP team: Google's website acceleration PHP skills are really nonsense _ PHP Tutorial

Source: Internet
Author: User
PHP team: Google's website acceleration PHP skills are really nonsense. 51CTO quick translation] The Google team shared their website acceleration tips last week, including some PHP performance skills. However, these PHP performance skills have caused an uproar in the PHP community.] The Google team shared their website acceleration tips last week, including some PHP performance skills. However, these PHP performance skills caused a storm in the PHP community, and the PHP team immediately wrote an open letter to these performance skills "catch insects ". For Google's suggestions, BKJIA has been sorted out over the past few days and published the article "acceleration, acceleration, and re-acceleration: a complete list of website acceleration techniques from Google". The second half of the fourth page focuses on PHP-related performance skills. you can familiarize yourself with this article before reading this article.

The following is a translation of letters from the PHP Group:

PHP team: suggestions in this articleAllAll are errors.

1. no reason. try not to copy variables.

The Zend Engine of PHP 4 and 5 uses a memory management system named "copy-on-write. That is to say, no matter how many times you assign the value of a variable to another variable, data will not be copied as long as you do not change the value. Example:

 
 
  1. $data = str_repeat("*", 512 * 1024); // synthesize 512K of data
  2. $memory_used_before = memory_get_usage();
  3. $more_data = $data;
  4. $memory_used_after = memory_get_usage();
  5. print "Before: {$memory_used_before}\nAfter: {$memory_used_after}\n";

PHP 5.3 with thread-safety and debugging functions:

Earlier: 853968

Later: 854236

PHP 5.2 without thread-safety and debugging functions:

Earlier: 581912

Later: 581976

That is, there is a 268-byte difference in the debugging mode, which is commonly used in the normal mode) there is a 64-byte difference. This is a far cry from the BKJIA Editor's note: In Google's original description, copying a variable will "double the memory consumption.

It should be noted that the PHP code does not allow you to echo or store the original content of the variables provided by the user without proper filtering.

2. use single quotes for long strings

The benchmark tests for PHP 5.2 and 5.3 show that although the double quotation marks use interpolation) and the single quotation marks use concatenation), the speed of the two is completely consistent, and even the double quotation marks are often faster ). When using a common string without variables, double quotation marks are superior in performance.

3. use echo instead of print

The running speed of these two methods depends on how your PHP is set on the host.

4. do not use concatenation together with echo)

The opposite is true. The new engine processes multiple echo methods, resulting in faster use of concatenation in echo.

5. replace if/else with switch/case

Finally, this suggestion is completely nonsense. Deciding where to use the switch/case or if/else depends entirely on the encoding habits, and their running speed is basically the same except in certain situations.

In fact, most of these suggestions are correct in older PHP versions, PHP 3 and very old PHP 4. However, these are definitely incorrect in the next generation of PHP.

  1. Acceleration, acceleration, and re-acceleration: a complete list of website acceleration techniques from Google
  2. Google launches the Web acceleration program to improve TCP/IP and HTTP protocols
  3. Google research team's latest report: speed is the most important on the Internet!
  4. Google will launch the developer community to improve Web performance
  5. Google launches webpage acceleration tool for developers Page Speed

Bytes. However, these PHP performance skills have caused an uproar in the PHP community...

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.