Skill: PHP optimization, buffering, compression practical solutions
As the popular Web programming language, the PHP biggest superiority is a speed. PHP4 already did in this aspect has been good, and you almost could not find it faster than the script programming language. However, if your application load large, and bandwidth is relatively small, or there are other bottlenecks affecting the performance of your server, then you may wish to try out for you the author of several prescription to see if it works.
First, code optimization
On a code optimization, perhaps you think is neat and clear code, but this is not the meaning of this, because if we seek rate, we should PHP source to be adjusted accordingly. Generally speaking is to remove redundant Notes, code unreadable. But this is a good accomplishment for programmers, it is inconceivable. Fortunately Zend Technologies announced the Zend engine optimization can help you do this. It is now free, but you must follow Zend Optimizer license. This product can be the engine optimized intermediate code.
This engine is relatively simple to install, download corresponding platform versions later, untied compressed files, and then in the php.ini file add the following two lines inside, restart the Web server, to get.
Zend_optimizer.optimization_level = 15
Zend_extension = “/ path / to / ZendOptimizer.so”
Zend_loader.enable = Off
If Win32 platform, it will be:
Zend_optimizer.optimization_level = 15
Zend_extension_ts = “C: /path / to / ZendOptimizer.dll”
Zend_loader.enable = Off
Ah! Not mistaken? How is three lines? In fact, the third line is optional. Seem to switch off because zend_loader can improve the speed, and is therefore worthy of this third line put php.ini. It must be noted that switching off is a prerequisite for the use of Zend you do not have encryption procedures.
Second, the buffer
If you want to further enhance the speed, we need to consider adopting buffer technology. Some optional solutions, including Zend Cache (test version), APC, and Afterburner Cache, such as another jpCache.
These are of a buffer module, the first time right. Php documents requested the intermediate code stored in the Web server’s memory, and then later on the request to return to “build good” version. This reduction of the disk to read and write, but in the memory, so this process can significantly improve application performance,
Off-the-shelf products such comparison, in the end choose whom?
Zend Cache is a good commercial product, in the first loading of those great PHP pages, you will clearly feel the speed increase, the server will leave more resources. Unfortunately, this product is to spend money, but in some cases, you may not mean the money.
Afterburner Cache is Bware Technologies products, is still in Beta version, and Zend Cashe appear to be the same, but it did not achieve good results Zend Cache, we can not and Zend engine optimization work together, but it is free, so I use this module.
APC (Alternative PHP Cache) is issued by the Community Connect has a free module can be used in production may seem environment.
Third, Web content compression
The increasingly crowded network, saving bandwidth like water conservation, is very much worth advocated. According to IETF standards, the majority of the browser should support the use of the contents of gzip compression. In other words you can use gzip compressed content sent to the browser, the browser will be transparent to extract the data.
Mod_gzip is Remote Communications Company introduced free Apache module, able to static Web content compression sent to the browser. For most static pages, this module is suitable. Although
Remotecommunications company said that this module supports all those who mod_php, mod_perl, mod what the dynamic content, but it still does not work, mod_gzip mailing list, the problem is estimated to 1.3.14.6 f can be resolved.
If the dynamic content compression, we can use class.gzip_encode.php, one in the script at the beginning and end of the use of PHP. For the entire site is in the php.ini auto_prepend and auto_append in which the function call. You can read the details of the procedures, which notes very well, and the author almost anything to tell you. But before use, your PHP to build support for the zlib.
For PHP 4.0.4, a new solution is the use of ob_gzhandler, to achieve the above categories and the same effect, as long as simple php.ini joined in the following sentence can be:
Output_handler = ob_gzhandler;
This allows PHP output caching, and compression of all output. If there is anything special reasons do not want to have all the contents of compressed output, can be used in the. Htaccess files by adding the following line in the corresponding directory under the file compression.
Php_value output_handler ob_gzhandler
Can be directly added to the code in PHP:
Ob_start ( “ob_gzhandler”);
The compression technology is very effective, but Netscape Communicator users, because Bunaiyasu graphics files, so do not seem to complete the jpeg and gif file compression, IE do not have this problem.
Conclusion:
This paper discussed the use of technology should be able to improve the performance of your site, but it should be noted that:
– PHP may not lead to bottlenecks reasons, carefully examined for other reasons (for example: Database)
– You can not regulate the server performance to the highest state. Therefore, in the buffer prior to complain of PHP and consider whether to upgrade the server, or to use dynamic load balancing technology.
– Do not underestimate the content compression, in your 100 Mb of internal online PHP applications that improve the speed, do not forget to use the modem users where 100 Kb blame your HTML page.

