? PHP acceleration principle and tool test

Source: Internet
Author: User
Tags apc apc module php write zts

PHP acceleration principle and tool testing

The relevant software of this experiment address: http://pan.baidu.com/s/1dDuwvE5

The first part. PHP Accelerated Classification:

I. Optimization of buffer layer level

1.xCache is to cache php opcode into the php extension in memory, XCache will avoid costly and unnecessary cost to recompile the same PHP code to deliver a page, which is a bit similar to accelerator, I always think their mechanism is the same, But Xcahce is an open source product [OpenSource].

2.Zend Accelerator Station in the middle of parsing and execution, when the page is first requested, the Zend engine parses it, and Accelerator puts the parsed image into memory, then executes and sends the message to the browser. It seems to be called Zend Cache.

The 3.Memcache Daemon (memcached) is a high-performance distributed object cache. The memcached is installed somewhere between the application and the data store, and it saves the object in RAM. Each cache hit replaces a round trip to the database server, making the application run faster. Great for access to a large number of sites to use.

4.APC (Alternative php Cache) it buffers php opcode rather than forcing PHP to re-interpret each script every time it executes.

Two Optimizing Code Levels

Zend Optimizer to the PHP source to make corresponding adjustments, such as removing some PHP comments, making the code easier to compile.

Three Programming-time-level optimizations

XDebug is something similar to software X-ray photos: It will delve into the application, exposing how it works internally, and revealing how the code spends its cycles. With XDebug metrics--not before--you can optimize your code to tune algorithms, reduce bottlenecks, and mitigate excessive memory usage.

The second part. Accelerated Demo

I'm here to give you a php5.4 version of the CentOS6.4 to demonstrate the acceleration effect of several different accelerators.

1.Opcache (built-in after php5.5);

2.Xcache;

3.APC (Alternative PHP Cache)

Before you start the demo, install php5.4:

1. Unpacking:

[Email protected] ~]# TAR-JXVF php-5.4.24.tar.bz2-c/usr/local/src/

2. Enter the/usr/local/src/directory to perform the installation:

[Email protected] php-5.4.24]#/configure--prefix=/usr/local/php--WITH-APXS2=/USR/LOCAL/APACHE/BIN/APXS-- With-mysql=/usr/local/mysql--with-mysqli=/usr/local/mysql/bin/mysql_config--enable-mbstring=all

3. Final make and make install:

[[email protected] php-5.4.24]# make && make install

4. Create PHP.ini, which is a file that indicates PHP extension functions, such as acceleration;

[email protected] php-5.4.24]# CP Php.ini-development/usr/local/php/lib/php.ini

5. Test the PHP connection to Apache:

Create a new static Web page under the httpd site home directory:

[Email protected] ~]# cd/usr/local/apache/htdocs/

[[email protected] htdocs]# vim index.php write as follows:

<?php

Phpinfo ();

?>

Access the server in a browser (http://server address);

If the PHP version information appears, the connection is normal.

A Zend Opcache:

1. Installation

[Email protected] ~]# TAR-XZF zendopcache-7.0.2.tgz-c/usr/local/src/

[Email protected] ~]# cd/usr/local/src/zendopcache-7.0.2/

To add an extension module for Pocache:

[Email protected] zendopcache-7.0.2]#/usr/local/php/bin/phpize

To perform the installation environment:

[Email protected] zendopcache-7.0.2]#/configure--with-php-config=/usr/local/php/bin/php-config

Perform the final installation:

[[email protected] zendopcache-7.0.2]# make && make install

2. Configuration

Edit php.ini File:

Vim/usr/local/php/lib/php.ini Add the following below:

[Opcache]

Zend_extension=/usr/local/php/lib/php/extensions/no-debug-zts-20100525/opcache.so

Opcache.enable=1

opcache.memory_consumption=128

Opcache.interned_strings_buffer=8

opcache.max_accelerated_files=4000

Opcache.revalidate_freq=60

Opcache.fast_shutdown=1

Opcache.enable_cli=1

3. Test the opcache.so call:

Open the browser, enter HTTP://192.168.2.101/(specific host IP), the Opcache module appears as normal;

4. Install the phpMyAdmin and use the httpd pressure test Tool AB for performance testing;

Install the phpMyAdmin and place it in the Apache site Master directory;

[Email protected] ~]# Unzip Phpmyadmin-4.1.5-all-languages.zip

[Email protected] ~]# MV Phpmyadmin-4.1.5-all-languages/usr/local/apache/htdocs/phpmyadmin

5. When Opcache is turned on, test:

[Email protected] ~]#/usr/local/apache/bin/ab-n 50000 http://localhost/phpmyadmin

Some of the test information is as follows, different machine test results are not the same:

5. Test when closing Opcache:

Close Opcache: Specifically, edit the/usr/local/php/lib/php.ini file, add the semicolon (;) to all the content we added to the Opcache, and restart the httpd service after saving [email protected] ~]# Service httpd restart.

Test again:

[Email protected] ~]#/usr/local/apache/bin/ab-n 50000 http://localhost/phpmyadmin

Some of the test information is as follows:

This contrasts the speed at which concurrent connection requests are processed when Opcache accelerates.

Two Xcache:

1. Install XCache:

[Email protected] ~]# TAR-ZXVF xcache-3.1.0.tar.gz-c/usr/local/src/

[Email protected] ~]# cd/usr/local/src/xcache-3.1.0

[Email protected] xcache-3.1.0]#/usr/local/php/bin/phpize

[Email protected] xcache-3.1.0]#/configure--enable-xcache--with-php-config=/usr/local/php/bin/php-config

[[email protected] xcache-3.1.0]# make && make install

Go to directory/usr/local/src/xcache-3.1.0,

[email protected] xcache-3.1.0]# cat Xcache.ini >>/usr/local/php/lib/php.ini

2. Edit the Usr/local/php/lib/php.ini file

Add the following line:

Extension=/usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so

3. Test the xcache.so call:

Open the browser, enter HTTP://192.168.2.101/(specific host IP), the XCache module appears as normal;

4. Test the acceleration effect:

1. Test when opening XCache:

[Email protected] ~]#/usr/local/apache/bin/ab-n 50000 http://localhost/phpmyadmin

Some of the test information is as follows, different machine test results are not the same:

2. Test when closing XCache:

Close XCache: Specifically, edit the/usr/local/php/lib/php.ini file, add the semicolon (;) to all the content we added to the XCache, and restart the httpd service after saving [email protected] ~]# Service httpd restart.

Test again:

[Email protected] ~]#/usr/local/apache/bin/ab-n 50000 http://localhost/phpmyadmin

Some of the test information is as follows:

By comparison, we can see the acceleration effect of xcache.

Three APC (Alternative PHP Cache)

1. Installation

TAR-ZXVF apc-3.1.10.tgz-c/usr/local/src/

[Email protected] apc-3.1.10]#/usr/local/php/bin/phpize

[Email protected] apc-3.1.10]#/configure--ENABLE-APC--enable-apc-mmap--with-php-config=/usr/local/php/bin/ Php-config

[[email protected] apc-3.1.10]# make && make install

2. Editor:/usr/local/php/lib/php.ini

Add in the following:

[APC]

Extension =/usr/local/php/lib/php/extensions/no-debug-zts-20100525/apc.so

apc.enabled = 1

Apc.shm_segments = 1

Apc.shm_size = 64M

Apc.optimization = 1

Apc.num_files_hint = 0

apc.ttl=7200

apc.user_ttl=7200

Apc.gc_ttl = 3600

Apc.cache_by_default = On

Save, restart httpd service;

3. Test load module situation;

Access server: HTTP://192.168.2.101/Results The APC module will appear.

4. Test acceleration:

1. When APC acceleration is turned on:

[Email protected] ~]#/usr/local/apache/bin/ab-n 50000 http://localhost/phpmyadmin

Some of the results are as follows:

2. When you turn off APC acceleration:

To turn off APC acceleration:

Edit/usr/local/php/lib/php.ini:

Block the addition of several lines of APC code; (preceded by a semicolon;)

restart httpd service; [[email protected] lib]# service httpd restart

View processing power,

[Email protected] ~]#/usr/local/apache/bin/ab-n 50000 http://localhost/phpmyadmin

Some of the results show:

You can see that the acceleration effect is not the first two obvious, but still can play a little acceleration ability.

Thank you for reading!

? PHP acceleration principle and tool test

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.