Oct 152009
 

Php default behaviour is always re-compile our script everytime accessed by users/browsers. eaccelerator can increases the performance of PHP scripts by caching them in their compiled state, so that the overhead of compiling is almost completely eliminated. It also optimizes scripts to speed up their execution. eAccelerator typically reduces server load and increases the speed of your PHP code by 1-10 times.

memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load.

Here’s how to install eaccelerator extension

$ wget http://bart.eaccelerator.net/source/0.9.6/eaccelerator-0.9.6-rc1.tar.bz2
$ tar xjf eaccelerator-0.9.6-rc1.tar.bz2
$ cd eaccelerator-0.9.6-rc1
$ phpize
$ ./configure
$ make
$ sudo make install
$ cd /var/cache
$ sudo mkdir eaccelerator
$ sudo chown -R apache:apache eaccelerator


Now create eaccelerator.ini in /etc/php.d/

$ sudo vi eaccelerator.ini
extension="eaccelerator.so"
eaccelerator.shm_size="16"
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="9"

Restart httpd

$ sudo /etc/init.d/httpd restart

Or

$ sudo service httpd restart

Install memcached and memcache extension

$ wget http://memcached.googlecode.com/files/memcached-1.4.2.tar.gz
$ wget http://pecl.php.net/get/memcache-2.2.5.tgz
$ tar xvzf memcached-1.4.2.tar.gz
$ cd memcached-1.4.2
$ ./configure
$ make
$ make install
$ tar xvzf memcache-2.2.5.tgz
$ cd memcache-2.2.5
$ phpize
$ ./configure
$ make
$ sudo make install
$ rpmbuild -ta memcached-1.4.2.tar.gz
$ sudo rpm -ivh /path/to/RPMS/memcached-1.4.2-1.i386.rpm

Start memcached as daemon

/etc/init.d/memcached start

Make memcached init script run automatically

$ sudo chkconfig --level 2345 memcached on

Create memcache.ini in /etc/php.d/

$ sudo vi memcache.ini
extension=memcache.so

Restart httpd

$ sudo /etc/init.d/httpd restart

Or

$ sudo service httpd restart

Now, test if eaccelerator and memcache extension is loaded

Create this small script in our httpd docroot

$ vi info.php
<?php phpinfo(); ?>

Open it from browser http://www.domain.tld/info.php

You should see something like this:

eaccelerator
php eaccelerator extension

memcache
php memcache extension

done, now your website is optimized with eaccelerator and memcache

  2 Responses to “Speeding up your website using eaccelerator and memcache/memcached”

Comments (2)
  1. How you change eaccelerator.shm_size to be 16..? my current setting indicates the value for that is just 1..

  2. that’s just an experiment for shared memory in eaccelerator 🙂

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.