Speed up PHP with eAccelerator [PHP / Apache Tutorial]

Status
Not open for further replies.

Baljeet

Member
Jan 31, 2011
76
0
Before you read:
My previous article about PHP optimization at the coding level can be located here:

I would recommend reading it and applying those strategies to get the most performance out of your PHP applications, this step will help on the hardware end lowering resource usage on Apache/Lighttpd children processes.

The differences can be shown greatly when compared to plain PHP execution, in this quick benchmark we will be measuring execution times of Drupal and in comparison to the alternate choice of opcode cacher, APC (using Apache Benchmark, with 1000 hits):

eaccel_bench.png

OpCode Caching:
From eAccelerator.net:
This step in optimizing your applications can be crucial for performance if your applications are larger and require higher resources per viewing, in the example above drupal was used to prove its usefulness on a high traffic website. Anything from an index, to Wordpress can improve in speed by storing the resulting compiled cache for use.

Downloading
First you must understand if you have the PHP 5 development tools, this can be checked by typing phpize anywhere in the console:
Code:
phpize -v
phpize_config.png

If this command runs you may skip this step, otherwise you can safely download it to your distribution with the following command(s):
Code:
Debian/Ubuntu:         sudo apt-get install php5-dev 
RHEL/CentOS/*SUSE:     yum install php-devel 
Gentoo:                emerge php5-dev 
Arch Linux:            pacman -S php5-dev
Once you confirm Apache/PHP's development tools are installed you may download the latest source of eAccelerator, this current package is newest as of December 2010:
Code:
cd /tmp
wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.zip
You will then be required to unzip the archive, this can be achieved with the command unzip:
Code:
unzip eaccelerator-0.9.6.1.zip
cd eaccelerator-0.9.6.1
Once you are within the eAccelerator folder, we will run the phpize command to configure the module according to your Zend and PHP versions:
Code:
phpize
./configure --enable-eaccelerator=shared
This enables eAccelerator to utilize shared memory and configures it to your system specifications as well. We are then done setting it up, you can build and install the library and application as so:
Code:
make
sudo make install
Installing into PHP 5
php_mysql_logo.png

During the "make install" processes the directory of which your PHP module was installed to will be listed at the bottom, note this directory for the next few steps so PHP can access the library.

We will now be editing php.ini so check where yours is located, most likely "/etc/php5/apache2/php.ini". Having trouble? Look at the phpinfo(); function output for the location:

php_ini_location.png

And edit it with your favourite editor. You can skip to the bottom of the file and add the following lines as you like:
Code:
zend_extension                  = "/usr/lib/php5/20100613+lfs/eaccelerator.so"
eaccelerator.shm_size           = "0"
eaccelerator.cache_dir          = "/var/cache/eaccelerator"
eaccelerator.enable             = "1"
eaccelerator.optimizer          = "1"
eaccelerator.check_mtime        = "1"
eaccelerator.debug              = "0"
eaccelerator.filter             = ""
eaccelerator.shm_max            = "0"
eaccelerator.shm_ttl            = "0"
eaccelerator.shm_prune_period   = "0"
eaccelerator.shm_only           = "0"
eaccelerator.compress           = "1"
eaccelerator.compress_level     = "7"
Notice our zend_extension directory, be sure to replace the first part with where your eaccelerator.so file is actually located as noted before. Once this is done we can restart apache 2 through any of the commands you were given, they may be one of these two:
Code:
httpd restart
(or)
apache2ctl restart
Assuming they did correctly restart without error, you may now create a page with the command phpinfo() in it. It can look like this:
Code:
<?php
    phpinfo();
?>
Be sure to remove the phpinfo page after you had verified its installation:

Assuming the module had loaded up correctly, scrolling down to the Zend/PHP version area it should state eaccelerator is installed!

The shm_ttl option set to 0 will allow the kernel option "/proc/sys/kernel/shmmax" dictate the maximum size before cached scripts are purged from the cache folder, this can default from 3-5 megabytes per process. This ends my CodeCall tutorial.
eaccel_config.png

All Credits goes to one who really made this...
 
Status
Not open for further replies.

Users who are viewing this thread

Top