In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Editor to share with you how to use PHP to speed up, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Code optimization
First, let's take a look at code optimization. Note that code optimization here does not mean making the code more beautiful, because it is probably well known that there is no need to discuss it any further; in addition, if you have taken speed into account, it is likely that you have already made some optimizations to the PHP source code.
However, there are some tools that can automatically help us with these complicated tasks, such as Zend Optimizer. Zend Optimizer is available free of charge from Zend Technologies, but you must agree to its license agreement and note that it is not distributed as GPL. Zend Optimizer takes the intermediate code generated by Zend Engine runtime compilation and optimizes it so that the intermediate code can be executed more efficiently.
The installation method of Zend Optimizer is very simple. You only need to download the precompiled version for your platform, add the following two lines of code to php.ini, and then restart the Web server:
Zend_optimizer.optimization_level=15 zend_extension= "/ path/to/ZendOptimizer.so" zend_loader.enable=Off
The extra third line of code added here is optional. Disabling zend_loader seems to make Zend Optimizer a little faster, so it's worth adding this line of code to php.ini. Note: you can disable zend_loader only if you are not using Zend Encoder Runtime.
Caching
If you want to improve the performance of your huge PHP applications, caching is also a good way. There are already many caching schemes to choose from, including: Zend Cache,APC, and Afterburner Cache.
All of these products belong to the "cache module". When * there are requests for .php files, they save the intermediate code of PHP in the memory of the Web server and then respond to subsequent requests with a "compiled" version. This approach does improve application performance because it minimizes disk access (the code has been read and parsed), and running code directly in memory makes the server much faster to respond to requests.
Of course, the caching module also monitors changes to the PHP source file and re-caches the page if necessary, thus preventing the user from getting a page that is still generated by outdated PHP code. Because cache modules can obviously reduce the load of the server and improve the response efficiency of PHP applications, they are not often suitable for websites with heavy load.
How to choose these cache products
Zend Cache is the commercial software of Zend Technologies, and Zend Technologies is the company that provides us with the PHP engine and free Zend Optimizer. Zend Cache really lives up to its reputation! For large PHP pages, you can feel that the speed will increase after * times, and the server will have more resources available. Unfortunately, this product is not free, but in some cases it is still good value for money.
Afterburner Cache is a free caching module from Bware Technologies, and this product is still in Beta. Afterburner Cache looks similar to Zend Cache, but its performance improvement is not (yet) comparable to that of Zend Cache, and it doesn't work with Zend Optimizer.
APC, which stands for Alternative PHP Cache, is another free cache block from Community Connect. This product is already stable enough for formal use, and it seems to greatly improve the speed of responding to requests.
Content compression
Earlier we discussed several ways to improve the performance of PHP applications. Let's take a look at another important factor that makes visitors feel that the site is too slow: download speed. If the PHP application runs on the internal Intranet and each client connects to the server at a speed of 100 MB/s, download speed should not be an issue. However, if the server still needs to serve slow Modem users, it is worth considering content compression.
Most browsers support content compression with gzip in accordance with the IETF standard. This means that you can use gzip to compress the content and send it to the browser, which decompresses the data and then displays the page, which is completely transparent to the user. As for server-side content compression, there are already many different methods available.
For example, mod_gzip, a free Apache module from Remote Communications, has the ability to compress static Web content for browsers that code for this type of content. Mod_gzip is very effective for most static Web content. Mod_gzip can be easily compiled into Apache or used as a DSO. According to Remote communications, mod_gzip can also compress dynamic content from mod_php, mod_perl, and so on.
I've tried again and again, but it doesn't seem to work. I have read a lot of forums and articles about mod_gzip and see that the next version of mod_gzip (maybe 1.3.14.6f) is expected to be solved. Before that, we could use mod_gzip in the static part of the website.
However, sometimes we do need to compress dynamic content, so we have to find other ways. One way is to use class.gzip_encode.php, a PHP class that can be used to compress the content of a page by calling some of its functions at the beginning and end of the PHP script. If you want to implement this scheme at the site level, you can call these functions from the auto_prepend and auto_append instructions in the php.ini file.
Although this method is effective, it undoubtedly brings more overhead for high-load websites. For detailed instructions on how to use this class, see its source code. Its source code description is quite perfect, and the author tells you everything you need to know.
PHP 4.0.4 has a new output cache handle, ob_gzhandler, which is similar to the previous class, but used differently. When using ob_gzhandler, you want to add the following to the php.ini:
Output_handler = ob_gzhandler
This line of code causes PHP to activate the output cache and compress everything it sends out. If for some reason you don't want to add this line of code to php.ini, you can also change the default server behavior (not compressed) through the .htaccess file in the directory where the PHP source file is located. The syntax is as follows:
Php_value output_handler ob_gzhandler
Or it can be called from PHP code, as follows:
Ob_start ("ob_gzhandler")
The method of using output cache handles is indeed very effective and does not impose any special load on the server. It is important to note, however, that Netscape Communicator does not support compressed graphics very well, so unless you can guarantee that all users will use IE browsers, you should prohibit compressing JPEG and GIF graphics. In general, this compression works for all other files, but it is recommended that you test it separately for various browsers, especially if you are using a special plug-in or data viewer.
Using the various techniques described above, you can significantly improve the performance of your site, but you should pay attention to:
PHP may or may not be the performance bottleneck. Be sure to carefully observe every factor related to application performance, such as databases, etc.
The simple use of this technology can only improve the performance of the Web server to a certain extent. So before blaming PHP and its cache, take a look at whether the server should be upgraded and whether load balancing technology can be introduced (which requires a large investment).
Don't underestimate the power of content compression. Although you see Web applications responding very quickly under a 100-MB/s LAN connection, users who use Modem connections will not, they will just complain that your 100-Kb HTML page is too large.
The above is all the contents of the article "how to speed up PHP". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.