Three tricks to get the PHP engine running Fast _php tutorial

Source: Internet
Author: User
Tags apc php source code
PHPThe unique syntax mixes C, Java, Perl, and PHP's self-innovative syntax. It can perform dynamic Web pages more quickly than CGI or Perl. Dynamic pages made with PHP are embedded in HTML documents to execute, compared to other programming languages, and are much more efficient than CGI, which fully generates HTML markup. Here are three ways to get the PHP engine running quickly.

First, the Code optimization

When it comes to code optimization, perhaps you think of a neat and clear code, but the meaning of this article is not here, because if you want to seek speed, the PHP source code should be adjusted accordingly. In general, the extra annotations are removed, making the code unreadable. But for a good-quality programmer, it's incredible. Fortunately, Zendtechnologies company released the Zend Optimization engine to help you do this. It is now free, but you must follow Zend optimizer license. This product can optimize the intermediate code generated by the engine.

Install this engine is relatively simple, download the corresponding version of the platform, unpack the compressed file, and then add the following two lines in the php.ini file, restart the Web server, it is done.

 
  
  
  1. Zend_optimizer.optimization_level=15
  2. zend_extension= "/path/to/zendoptimizer.so"

If it is the Win32 platform should be:

 
  
  
  1. Zend_optimizer.optimization_level=15
  2. zend_extension_ts= "C:\path\to\ZendOptimizer.dll"

In fact, the third line is optional. It's worth putting this third line into php.ini because it looks like turning the zend_loader off can improve a bit of speed. It is important to note that you are not using the Zend encryption program when you turn off the condition.

Second, buffer

If we want to increase our speed further, we need to consider using buffering technology. There are some optional solutions, including Zend cache (Beta version), APC, and Afterburner cache, plus jpcache.

All of these are buffer modules, which they put in the memory of the WEB server for the first time a request for a. php file was made, and then return a "compiled" version for subsequent requests. Because this reduces the disk read and write, and all in memory work, so this process can significantly improve application performance, ready-made such products more, in the end choose who?

    • Zend Cache is a good commercial product, after the first load of those large PHP pages, you will obviously feel the speed of ascension, the server will set aside more resources. It's a pity that this product is going to cost money, but in some cases you don't want to be stingy with the silver.
    • The Afterburner cache is a bware Technologies product that is currently in Beta and looks like Zend Cashe, but it does not work as well as Zend Cache, and it cannot be worked with the Zend optimization engine, but Yes it is free, so I used this module.
    • APC (Alternative PHP Cache) is another free module released by Community Connect and looks like it can be used in production environments.

Third, Web content compression

For an increasingly congested network, saving bandwidth is just as important as saving water. Depending on the IETF standard, most browsers should support content that uses gzip compression. In other words, you can send gzip compressed content to the browser, the browser will transparently unzip the data.

Mod_gzip is a free Apache module launched by Remote Communications, which compresses and sends static Web content to the browser. This module is suitable for most static web pages. Although the remote communications said that the module supported all those mod_php, mod_perl,mod what generated the dynamic content, but still does not seem to work, from the Mod_gzip mailing list, This problem is estimated to be solved by 1.3.14.6f.

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 the script. For the entire Web site is the function that is called in PHP.ini's Auto_prepend and Auto_append. You can read this kind of program in detail, the program is very well commented, the author almost told you everything. But before using it, your PHP will be compiled to support zlib.

For PHP 5, a new solution is to use Ob_gzhandler, to achieve the same effect as the above class, as long as the simple in the php.ini to add the following sentence:

 
  
  

This enables PHP to activate the output buffer and compress all output. If there is any special reason not to let all the content compressed output, you can use the following line in the. htaccess file to compress the files in the corresponding directory.

Php_value Output_handler Ob_gzhandler

You can also add directly to the PHP code:

 
  
  
  1. Ob_start ("Ob_gzhandler"

This compression technique is very effective, but for Netscape Communicator users, because the graphics file cannot be compressed, it does not appear to be a complete send, so you must turn off compression of JPEG and GIF files, IE does not have this problem.

Iv. Conclusion

Using the techniques discussed in this article should improve the performance of your website, but it is important to note that:

PHP may not be the cause of the bottleneck, check for other reasons (for example: database)

You can't tune server performance to the highest state. Therefore, before complaining about PHP and its buffering, consider whether to upgrade the server or use dynamic load balancing technology.

Don't underestimate content compression, and when you see the speed increase of your PHP app on your internal network, don't forget where your modem users are complaining about your 100Kb HTML page.

Hope that through the above content of the introduction, can bring you help.


http://www.bkjia.com/PHPjc/445766.html www.bkjia.com true http://www.bkjia.com/PHPjc/445766.html techarticle PHP's unique syntax mixes C, Java, Perl, and PHP's self-innovative syntax. It can perform dynamic Web pages more quickly than CGI or Perl. Using PHP to make dynamic pages with other programming languages ...

  • 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.