PHP Engine Optimization

Source: Internet
Author: User
Tags imagemagick php and mysql php source code phpinfo zts install perl zend

PHP Engine Optimization

6.1.php Engine Cache optimization

First, there are 2 main factors that affect PHP efficiency. One: 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


View Nginx Version


View Apache version


View Apache Compilation parameters


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


Echo $LC _all

Yum Install Perl-cpan

(1) Eaccelerator

Tar XF eaccelerator-0.9.6.tar.bz2

CD eaccelerator-0.9.6


./configure \

--enable-eaccelerator=shared \



Make install

Make install completes to display such a directory, recorded


(2) XCache



./configure \

--enable-xcache \



Make install

Note: XCache and eaccelerator just put one on.

PHP Cache Accelerator Software types


How to choose

Recommended Xcache,eaccelerator Two Select a



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




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


./configure \

--with-php-config=/application/php/bin/php-config \



Make install


6.1.4 installation of image processing programs and Imagick extension modules

BEGIN failed--compilation aborted at 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 install


Tar XF imagick-2.3.0.tgz

CD imagick-2.3.0




Make install

[Email protected] imagick-2.3.0]# ls/application/php5.3.27/lib/php/extensions/no-debug-zts-20090626/

6.1.5 Configuration Extension



819 extension_dir = "/application/php5.3.27/lib/php/extensions/no-debug-zts-20090626/"

Trailing line Append

1919; ----------------------

1920x1080 Extension =

1921 Extension =

1922 Extension =


Quick copy:

Extension =

Extension =

Extension =

(1) Configuring the Eaccelerator plugin

1. Configuring the Eaccelerator Cache directory


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


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/

Note 6; zend_extension_ts = C:/php/extensions/php_xcache.dll

Uncomment 8 extension =

Cat/home/xiaoyi/tools/xcache-1.3.2/xcache.ini >>/application/php/lib/php.ini

Finally passed Phpinfo (); Check both extensions are installed


Phpinfo ();



Tar XF webbench-1.5.tar.gz

CD webbench-1.5


Make install

565 webbench-c 100-t

566 webbench-c 200-t

567 webbench-c 300-t

568 Webbench-c 400-t

569 webbench-c 500-t

570 Webbench-c 500-t

571 webbench-c 600-t

572 Webbench-c 650-t

573 Webbench-c 550-t

574 webbench-c 520-t

575 Webbench-c 510-t

Forgot to stress test the site before installing Eaccelerator--

This article is from the "Yi Xiaoyi" blog, make sure to keep this source

PHP Engine Optimization

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