PHP Team: Google offers website acceleration php tips It's nonsense. _php Tutorial

Source: Internet
Author: User
Tags vars
Bkjia the Google Group last week shared its website acceleration tips, including some PHP performance tips. However, these PHP performance tips in the PHP community caused a stir, the PHP team immediately wrote an open letter to these performance skills "catch worms." About Google's recommendations, Bkjia these days to do the finishing, make the article "Accelerate, accelerate, and then accelerate: from Google's website acceleration skills Daquan." The second half of the fourth page is about PHP-related performance techniques that you can familiarize yourself with before reading this article.

Here is a letter from the PHP team:

PHP Team: The recommendations in this article are all wrong.

1. Try not to copy variables for no reason

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

 
  
  
  1. $datastr_repeat("*"//synthesize 512K of data
  2. $memory _used_before = Memory_get_usage ();
  3. $more _data$data;
  4. $memory _used_after = Memory_get_usage ();
  5. "before: {$memory _used_before}\nafter: {$memory _used_after}\n" ;

PHP 5.3 with Thread-safety and debug function:

Before: 853968

After: 854236

PHP 5.2 without Thread-safety and debug function:

Before: 581912

After: 581976

That is, there is a 268-byte difference in debug mode, which is generally used in normal mode) with a 64-byte difference. This is in contrast to the Bkjia editor's note in Google: the copy variable "causes double memory consumption" in the description of Google's original text.

It is important to note that the PHP code strongly prohibits the use of the user-supplied variable to echo or store the original content without proper filtering.

2. Use single quotes for long strings

Benchmarks for PHP 5.2 and 5.3 show that although double quotes use tamper interpolation and single quotes using chained concatenation), the two rates are exactly the same and even double quotes are often faster). When using a normal string that does not contain a variable, the performance of using double quotes is significantly superior.

3. Use echo rather than print

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

4. Do not use the concatenation chain with Echo)

The opposite is true. The new engine handles multiple echo methods, causing the use of concatenation in echo to actually be faster.

5. Replace If/else with Switch/case

Finally, the proposal is a complete nonsense. Deciding where to use switch/case or if/else depends entirely on the coding habit, and they run at the same speed, except in certain specific cases.

In fact, most of these suggestions are correct in the older PHP version of PHP 3 and the very old version of PHP 4, but under the new generation of PHP, these are definitely wrong.

    1. Accelerate, accelerate, and accelerate: Website acceleration tips from Google
    2. Google launches Web Acceleration program to improve TCP/IP and HTTP protocols
    3. Google Research Group latest report: On the Internet, speed is the most important!
    4. Google launches developer community to improve Web performance
    5. Google launches Web Acceleration tool for Developers page speed

http://www.bkjia.com/PHPjc/589139.html www.bkjia.com true http://www.bkjia.com/PHPjc/589139.html techarticle 51CTO Quick Translation "The Google Group shared its website acceleration tips last week, including some of the PHP performance tips. However, these PHP performance tips have caused a flurry of fuss in the PHP community ...

  • Related Article

    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.