LAMP server performance optimization techniques-accelerating PHP

Source: Internet
Author: User

Apache server optimization, PHP optimization, and Mysql Optimization

1. Use eaccelerator

We have introduced the optimization of the Apache server. If you have browsed the PHP web page, you may find: How does PHP speed slowly? What is the matter? Isn't PHP a fast response? How can this happen slowly? This is because PHP program code calls too many function libraries, and each call to these function libraries needs to be read by the hard disk. Is there any way to speed up PHP Execution. If we can read these function libraries in the hard disk into the Cache, the memory speed is much faster than that of the hard disk. In this way, it can certainly increase the speed.

2. download and install the software:

Wget http://internap.dl.sourceforge.net/sourceforge/eaccelerator/eaccelerator-0.9.3.tar.bz2

Tar jxf eaccelerator-0.9.3.tar.bz2

 
 
  1. /usr/local/bin/phpize
  2. ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/bin/php-config
  3. make;make install

Modify the/etc/php. ini file and add the following content:

 
 
  1. extension="/PATH/TO/eaccelerator.so"
  2. eaccelerator.shm_size="16"
  3. eaccelerator.cache_dir="/tmp/eaccelerator"
  4. eaccelerator.enable="1"
  5. eaccelerator.optimizer="1"
  6. eaccelerator.check_mtime="1"
  7. eaccelerator.debug="0"
  8. eaccelerator.filter=""
  9. eaccelerator.shm_max="0"
  10. eaccelerator.shm_ttl="0"
  11. eaccelerator.shm_prune_period="0"
  12. eaccelerator.shm_only="0"
  13. eaccelerator.compress="1"
  14. eaccelerator.compress_level="9"

Then create a directory for fast data access:

 
 
  1. mkdir /tmp/eAccelerator
  2. chmod 0777 /tmp/eAccelerator

Restart the Apache server:

 
 
  1. /etc/rc.d/init.d/httpd restart

Open the Web page in the lynx browser and check that phpinfo () shows figure 7, which indicates that the installation is successful.

Figure 7 enable eAccelerator

You can see that the eAccelerator is enabled. The following uses the AB command: Apache HTTP server performance testing tool, which is a tool to test your Apache http server, you can use this tool to specify the number of requests sent to apache within a unit of time to see the performance of your Apache and machine cooperation. The command is as follows:

 
 
  1. /home/apache/bin/ab -c 20 -n100 –w http://localhost/phpinfo >1.html

-C: the number of requests sent to the server at the same time. By default, only one http request is executed at a time.

-N: number of requests sent when a test session is executed.

-W: print the output result to the HTML table. The default table is a black box with n rows in white.

The requests per second (rps) of the test data of apacheap refers to the number of pages returned by the server per second. After comparison, the web page speed is significantly faster with eAccelerator. Figure 8 test results of the lynx browser in HTML format.

Figure 8 HTML format test results

3. Use Zend Optimizer

Zend Optimizer uses code optimization methods to speed up the execution of PHP 4.0 applications. The principle of implementation is to optimize the code generated by the Run-Time Compiler before it is finally executed. Generally, the execution of a PHP program using Zend Optimizer is 40% to 100% faster than that without Zend Optimizer. This means that the visitor of the website can browse the webpage faster, so as to complete more transactions and create better customer satisfaction. Faster response also means saving hardware investment and enhancing the services provided by the website. Therefore, using Zend Optimizer improves the profitability of e-commerce. Zend Optimizer can bring many benefits to PHP users, especially those who operate websites. Quick running of the PHP program can significantly reduce the server's CPU load and reduce the response time by half, that is, the time between the visitor clicking the link to the server and reading the page.

Zend Optimizer installation is a fool. The installation wizard automatically modifies php. ini based on your choice to help you start this engine.

Download and install the software:

Wget http://downloads.zend.com/optimizer/3.0.0/ZendOptimizer-3.0.0-linux-glibc21-i386.tar.gz

Gunzip ZendOptimizer-3.0.0-linux-glibc21-i386.tar.gz

Tar vxf ZendOptimizer-3.0.0-linux-glibc21-i386.tar

Cd ZendOptimizer-3.0.0-linux-glibc21-i386

 
 
  1. ./install

Figure 9 Zend Optimizer Installation Wizard

Restart the Apache server:

 
 
  1. /etc/rc.d/init.d/httpd restart

On the Web page, you can see the figure through phpinfo (), indicating that Zend Optimizer is successfully installed.

Figure 10 Zend Optimizer installed successfully

Then you can run the AB command to perform another test. The Siege (http://www.joedog.org/siege/) can also be used for testing, which is a stress testing and evaluation tool designed for WEB development which assesses the application's affordability under pressure: you can perform concurrent access to multiple users on a WEB site according to the configuration, record the corresponding time of all the request processes of each user, and repeat it with a certain number of concurrent accesses.

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.