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):
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:
If this command runs you may skip this step, otherwise you can safely download it to your distribution with the following command(s):
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:
You will then be required to unzip the archive, this can be achieved with the command unzip:
Once you are within the eAccelerator folder, we will run the phpize command to configure the module according to your Zend and PHP versions:
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:
Installing into PHP 5
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:
And edit it with your favourite editor. You can skip to the bottom of the file and add the following lines as you like:
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:
Assuming they did correctly restart without error, you may now create a page with the command phpinfo() in it. It can look like this:
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.
All Credits goes to one who really made this...
My previous article about PHP optimization at the coding level can be located here:
You must be registered for see links
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):
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
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
Code:
cd /tmp
wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.zip
Code:
unzip eaccelerator-0.9.6.1.zip
cd eaccelerator-0.9.6.1
Code:
phpize
./configure --enable-eaccelerator=shared
Code:
make
sudo make install
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:
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"
Code:
httpd restart
(or)
apache2ctl restart
Code:
<?php
phpinfo();
?>
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.
All Credits goes to one who really made this...