PHP Engine Optimization
6.1.php Engine Cache optimization
First, there are 2 main factors that affect PHP efficiency. One: libphp5.so need to compile PHP source code to become opcode tree (opcode); second: PHP needs to read and write to the database, the database concurrency is very low.
So the PHP cache accelerator is to solve the first reason above, the opcode content cache, the purpose is to prevent PHP every request to compile PHP code repeatedly, because on the high-traffic site, a large number of repeated compilation will be a lot of resources and time events, So the bottleneck here is that PHP's repeated compilation affects both the corresponding speed and the server load, in order to solve this problem, the PHP accelerator was born
Solve the problem between PHP and MySQL, using the memcache, between PHP and MySQL to set up a cache, effectively improve the number of database concurrency.
View Nginx Compilation parameters
/application/nginx/sbin/nginx-v
View Nginx Version
/application/nginx/sbin/nginx-v
View Apache version
/application/apache/bin/apachectl-v
View Apache Compilation parameters
Cat/application/apache/build/config.nice
View MySQL Compilation parameters
grep configure_line/application/mysql/bin/mysqlbug
View PHP Compilation parameters
/application/php/bin/php-i | grep Configure
6.1.1 Installing the PHP engine cache accelerator
echo ' Export lc_all=c ' >>/etc/profile
Source/etc/profile
Echo $LC _all
Yum Install Perl-cpan
(1) Eaccelerator
Tar XF eaccelerator-0.9.6.tar.bz2
CD eaccelerator-0.9.6
/application/php/bin/phpize
./configure \
--enable-eaccelerator=shared \
--with-php-config=/application/php/bin/php-config
Make
Make install
Make install completes to display such a directory, recorded
ls/application/php5.3.27/lib/php/extensions/no-debug-zts-20090626/
(2) XCache
Http://xcache.lighttpd.net
/application/php/bin/phpize
./configure \
--enable-xcache \
--with-php-config=/application/php/bin/php-config
Make
Make install
Note: XCache and eaccelerator just put one on.
PHP Cache Accelerator Software types
Xcache,eaccelerator,zend,apc
How to choose
Recommended Xcache,eaccelerator Two Select a
Xcache>eaccelerator
Reason:
A.xcache faster and more efficient
B.xcache Development More Active
OpCode cache acceleration Software ↑
6.1.2 Database Cache Memcache
PHP Bottlenecks:
1. The PHP code itself needs to be parsed
2. Need to request database, database concurrency is relatively low
Solution: Set up cache between PHP and database, memcached (client software)
Service-Side memcached-1.4.3.tar.gz
Client memcache-2.2.5.tgz
Tar XF memcache-2.2.5.tgz
CD memcache-2.2.5
/application/php/bin/phpize
./configure--with-php-config=/application/php/bin/php-config
ls/application/php5.3.27/lib/php/extensions/no-debug-zts-20090626/
6.1.3pdo_mysql Expansion Module
The PDO extension defines a lightweight, consistent interface for the PHP Access database, which provides a data access abstraction layer so that queries and data can be executed through consistent functions, regardless of the database used
Tar XF pdo_mysql-1.0.2.tgz
CD pdo_mysql-1.0.2
/application/php/bin/phpize
./configure \
--with-php-config=/application/php/bin/php-config \
--with-pdo-mysql=/application/mysql
Make
Make install
ls/application/php5.3.27/lib/php/extensions/no-debug-zts-20090626/
6.1.4 installation of image processing programs and Imagick extension modules
BEGIN failed--compilation aborted at makefile.pl Line 24.
MAKE[1]: * * * [perlmagick/makefile] Error 2
MAKE[1]: Leaving directory '/home/xiaoyi/tools/imagemagick-6.5.1-2 '
Make: * * * [ALL] Error 2
Yum Install Perl-cpan-y
Tar XF ImageMagick.tar.gz
CD imagemagick-6.5.1-2/
Make
Make install
Cd..
Tar XF imagick-2.3.0.tgz
CD imagick-2.3.0
/application/php/bin/phpize
./configure--with-php-config=/application/php/bin/php-config
Make
Make install
[Email protected] imagick-2.3.0]# ls/application/php5.3.27/lib/php/extensions/no-debug-zts-20090626/
eaccelerator.so imagick.so memcache.so pdo_mysql.so
6.1.5 Configuration Extension
Cp/application/php/lib/php.ini/application/php/lib/php.ini.bak
Vim/application/php/lib/php.ini
819 extension_dir = "/application/php5.3.27/lib/php/extensions/no-debug-zts-20090626/"
Trailing line Append
1919; ----------------------
1920x1080 Extension = memcache.so
1921 Extension = pdo_mysql.so
1922 Extension = imagick.so
1923;-----------------------
Quick copy:
Extension = memcache.so
Extension = pdo_mysql.so
Extension = imagick.so
(1) Configuring the Eaccelerator plugin
1. Configuring the Eaccelerator Cache directory
Mkdir-p/tmp/eaccelerator
Chown Ett/tmp/eaccelerator-r
This directory can be stored using the TMPFS memory file system, SSD
Cat >>/application/php/lib/php.ini <<eof
[Eaccelerator]
Extension=eaccelerator.so
Eaccelerator.shm_size= "64"
Eaccelerator.cache_dir= "/tmp/eaccelerator"
eaccelerator.enable= "1"
Eaccelerator.optimizer= "1"
Eaccelerator.check_mtime= "1"
eaccelerator.debug= "0"
Eaccelerator.filter= ""
eaccelerator.shm_max= "0"
Eaccelerator.shm_ttl= "3600"
eaccelerator.shm_prune_period= "3600"
eaccelerator.shm_only= "0"
eaccelerator.compress= "1"
Eaccelerator.compress_level= "9"
Eof
If Zend [Eaccelerator] is configured to be placed before the content configuration of Zend
[Email protected] imagick-2.3.0]#/application/php/bin/php-v
PHP 5.3.27 (CLI) (BUILT:APR 13 2015 10:53:41)
Copyright (c) 1997-2013 the PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
With Eaccelerator v0.9.6, Copyright (c) 2004-2010 eaccelerator, by Eaccelerator
(2) Configure XCache plug-in acceleration
CP Php-5.3.27/php.ini-production/application/php/lib/php.ini
Vim/home/xiaoyi/tools/xcache-1.3.2/xcache.ini edit Modify XCache configuration parameters
Note 3; zend_extension =/usr/local/lib/php/extensions/non-debug-non-zts-xxx/xcache.so
Note 6; zend_extension_ts = C:/php/extensions/php_xcache.dll
Uncomment 8 extension = xcache.so
Cat/home/xiaoyi/tools/xcache-1.3.2/xcache.ini >>/application/php/lib/php.ini
Finally passed Phpinfo (); Check both extensions are installed
<?php
Phpinfo ();
?>
wget http://blog.zyan.cc/soft/linux/webbench/webbench-1.5.tar.gz
Tar XF webbench-1.5.tar.gz
CD webbench-1.5
Make
Make install
565 webbench-c 100-t http://bbs.etiantian.org/forum.php
566 webbench-c 200-t http://bbs.etiantian.org/forum.php
567 webbench-c 300-t http://bbs.etiantian.org/forum.php
568 Webbench-c 400-t http://bbs.etiantian.org/forum.php
569 webbench-c 500-t http://bbs.etiantian.org/forum.php
570 Webbench-c 500-t http://bbs.etiantian.org/forum.php
571 webbench-c 600-t http://bbs.etiantian.org/forum.php
572 Webbench-c 650-t http://bbs.etiantian.org/forum.php
573 Webbench-c 550-t http://bbs.etiantian.org/forum.php
574 webbench-c 520-t http://bbs.etiantian.org/forum.php
575 Webbench-c 510-t http://bbs.etiantian.org/forum.php
Forgot to stress test the site before installing Eaccelerator--
This article is from the "Yi Xiaoyi" blog, make sure to keep this source http://gongxiaoyi.blog.51cto.com/7325139/1825450
PHP Engine Optimization