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:
- $datastr_repeat("*"//synthesize 512K of data
- $memory _used_before = Memory_get_usage ();
- $more _data$data;
- $memory _used_after = Memory_get_usage ();
- "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.
- Accelerate, accelerate, and accelerate: Website acceleration tips from Google
- Google launches Web Acceleration program to improve TCP/IP and HTTP protocols
- Google Research Group latest report: On the Internet, speed is the most important!
- Google launches developer community to improve Web performance
- 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 ...