As a popular Web programming language, PHP's biggest advantage is speed. PHP4 has done very well in this area and you can hardly find a faster scripting language. But if your application load is very large, and the bandwidth is relatively small, or other bottlenecks affect your server performance, then you may wish to try the author for you to prescribe a few prescriptions to see if it is efficacious.
As a popular Web programming language, PHP's biggest advantage is speed. PHP4 has done very well in this area and you can hardly find a faster scripting language. But if your application load is very large, and the bandwidth is relatively small, or other bottlenecks affect your server performance, then you may wish to try the author for you to prescribe a few prescriptions to see if it is efficacious.
First, code optimization
When it comes to code optimization, perhaps you think of neat and clear code, but the meaning of this article is not here, because if you want to find the speed, it is necessary to adjust the PHP source code accordingly. The general thing is to get rid of unnecessary annotations and make the code unreadable. But this is incredible for a good quality programmer. Fortunately Zend Technologies company released a Zend optimization engine that can help you do this. It's free now, but you have to follow Zend Optimizer license. This product can be optimized for the intermediate code generated by the engine.
Install this engine is relatively simple, download the version of the corresponding platform after the release of compressed files, and then add the following two lines in the php.ini file, restart the Web server, it is done.
Zend_optimizer.optimization_level=15
zend_extension= "/path/to/zendoptimizer.so"
Zend_loader.enable=off
If it's a Win32 platform, it should be:
Zend_optimizer.optimization_level=15
Zend_extension_ts= "C:\\path\\to\\zendoptimizer.dll"
Zend_loader.enable=off
Ah! No mistake, right? What's three lines? In fact, the third line is optional. Because it looks like turning the zend_loader off can improve the speed, it's worth putting the third line in the php.ini. Note that the prerequisite for shutting down is that you are not using the Zend encryption program.
Second, buffer
If we want to increase speed further, we need to consider the use of buffer technology. There are some alternative solutions, including Zend cache (Beta version), APC, and Afterburner cache, plus jpcache.
These are all part of the buffer module that they put on for the first time. The intermediate code generated by the PHP file request is stored in the WEB server's memory and then returned to a "compiled" version of the subsequent request. Because this reduces disk reads and writes, and all work in memory, this process can significantly improve application performance,
There are a lot of such products available, in the end choose who?
Zend Cache is a good commercial product, in the first load of those large PHP page, you will obviously feel the speed of ascension, the server will set aside more resources. Unfortunately, this product is to spend money, but in some cases, you should not be stingy with these silver.
The Afterburner Cache is a Bware technologies product that is currently in Beta and appears to be the same as Zend Cashe, but it does not work as well as Zend Cache, nor with the Zend optimization engine , but it's free, so I used this module.
APC (Alternative PHP Cache) is another free module released by Community Connect, which looks like it can be used in a production environment.
Third, Web content compression
For an increasingly congested network, bandwidth savings are as much worth advocating as water conservation. According to IETF standards, most browsers should support content that uses gzip compression. That is, you can send the content with gzip compressed to the browser, the browser will be transparent to extract data.
Mod_gzip is a free Apache module launched by Remote Communications, which compresses static web content and sends it to browsers. This module is suitable for most static web pages. Although
Remotecommunications said the module supports all of the mod_php, mod_perl,mod what generated dynamic content, but does not seem to work, from the Mod_gzip mailing list, This problem is estimated to be 1.3.14.6f to solve.
If we want to compress dynamic content, we can use Class.gzip_encode. PHP, a PHP class that is used at the beginning and end of a script. For the entire site, the functions are called in the php.ini Auto_prepend and Auto_append. You can read the program in detail, the program is well commented, and the author has almost told you everything. However, before using, your PHP will be compiled to support zlib.
For PHP 4.0.4, a new solution is to use Ob_gzhandler to achieve the same effect as the class above, as long as the following words are simply added to the php.ini:
Output_handler = Ob_gzhandler;
This allows PHP to activate the output buffer and compress all output. If there is any special reason not to let all the content compression output, you can use in the. htAccess file to add the following line, the corresponding directory to compress the files.
Php_value Output_handler Ob_gzhandler
You can also add it directly to your PHP code:
Ob_start ("Ob_gzhandler");
This compression technology is very effective, but for Netscape Communicator users, because the graphics file can not be compressed, so it appears that there is no full send, so you must turn off the JPEG and GIF file compression, IE does not have this problem.
Conclusion:
Using the techniques discussed in this article should improve your site's performance, but you need to be aware of:
-PHP may not be the cause of the bottleneck, carefully check for other reasons (for example: database)
-You cannot adjust server performance to the highest state. So before blaming PHP and its buffers, consider whether to upgrade the server or adopt dynamic load balancing technology (which is a lot of money).
-Do not underestimate content compression, when you see the speed of PHP applications on your MB intranet, don't forget where users of your modem are complaining about your 100Kb HTML page.