home forums resources search newsjoinmembers: 6375
Hiveminds Network PHP Flash Java Ruby Windows Linux
Hiveminds | Thu, 2007-08-30 07:33  tags: , ,

EAccelerator is a free open-source PHP accelarator, optimizer, and dynamic content cache. It 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. eAccelarator typically reduces server load and increases the speed of your PHP code by 1-10 times.

This is the second part of a series on how to install PHP on a shared web host and optimize it with a cache handler. Here we take a look at installing eAccelarator.

eAccelarator was born in December 2004 as a fork of the Turck MMCache project. Turck MMCache was created by Dmitry Stogov and much of the eAccelarator code is still based on his work.

eAccelarator is still under development. The latest release, 0.9.5, supports PHP 4 and all PHP 5 releases including 5.2. In older releases, the encoder will only work with PHP versions from the 4.x.x branch. eAccelarator will not work with any other versions of PHP.

Get started by saving the following code to *.sh. FTP upload the script to your account root. Then set the permissions via FTP to 755. Start putty or whatever shell gui you are using and run the script in your shell by typing ./nameofscript.sh. If problems are encountered the script will stop. Fix the problems and run the script again. I have run this script several times without any errors. But is perfect. This is a much better and less time consuming way of using SHELL. Typing line by line and troubleshooting along the way is only for the sadistic.

#!/bin/sh

# Abort on any errors
set -e

# Where do you want all this stuff built? I'd recommend picking a local
# filesystem.
# ***Don't pick a directory that already exists!***  We clean up after
# ourselves at the end!
SRCDIR=${HOME}/source

# And where should it be installed?
INSTALLDIR=${HOME}/php5/

# Set DISTDIR to somewhere persistent, if you plan to muck around with this
# script and run it several times!
DISTDIR=${HOME}/dist

# Pre-download clean up!!!!
rm -fr $SRCDIR $DISTDIR

# Update version information here.
AUTOCONF="autoconf-2.61"
AUTOMAKE="automake-1.9.6"
EAC="eaccelerator-0.9.5"

# What PHP features do you want enabled?
EACFEATURES="--prefix=${INSTALLDIR} \
--enable-eaccelerator=shared \
--with-php-config=$PHP_PREFIX/bin/php-config"



# ---- end of user-editable bits. Hopefully! ----

# Push the install dir's bin directory into the path
export PATH=${INSTALLDIR}/bin:$PATH

#setup directories
mkdir -p ${SRCDIR}
mkdir -p ${INSTALLDIR}
mkdir -p ${DISTDIR}
cd ${DISTDIR}

# Get all the required packages
wget -c http://ftp.gnu.org/gnu/autoconf/${AUTOCONF}.tar.gz
wget -c http://ftp.gnu.org/gnu/automake/${AUTOMAKE}.tar.gz
wget -c http://bart.eaccelerator.net/source/0.9.5/${EAC}.tar.bz2


echo ---------- Unpacking downloaded archives. This process may take several minutes! ----------

cd ${SRCDIR}
# Unpack them all
echo Extracting ${AUTOCONF}...
tar xzf ${DISTDIR}/${AUTOCONF}.tar.gz
echo Done.
echo Extracting ${AUTOMAKE}...
tar xzf ${DISTDIR}/${AUTOMAKE}.tar.gz
echo Done.
echo Extracting ${EAC}...
tar -xjf ${DISTDIR}/${EAC}.tar.bz2
echo Done.

export PATH=${SRCDIR}/bin:$PATH
export PHP_PREFIX=${INSTALLDIR}/bin


# Build them in the required order to satisfy dependencies.

#AUTOCONF
cd ${SRCDIR}/${AUTOCONF}
./configure --prefix=${SRCDIR}
# make clean
make
make install

#AUTOMAKE
cd ${SRCDIR}/${AUTOMAKE}
./configure --prefix=${SRCDIR}
# make clean
make
make install

#EAC
cd ${SRCDIR}/${EAC}
$PHP_PREFIX/phpize
./configure --enable-eaccelerator=shared  --with-eaccelerator-info --with-php-config=$PHP_PREFIX/php-config
# make clean
make


#copy config file
cp modules/eaccelerator.so  ${INSTALLDIR}/lib/php/extensions/eaccelerator.so
mkdir -p ~/tmp/eaccelerator


rm -fr $SRCDIR $DISTDIR
echo ---------- INSTALL COMPLETE! ----------

Now to set up your PHP. You only need to make additions to the php.ini. Since you should be running PHP in FCGI mode there is no restarting of Apache needed.

[eaccelerator]

extension="eaccelerator.so"
eaccelerator.allowed_admin_path="/home/user/www.domain.co.uk"
eaccelerator.shm_size="16"
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="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

If everything is fine then you should be seeing eAccelerator information as shown in these images

Many that install eAccelarator immediately look in the temp file directory expecting to see files. They take this as a sign that eAccelerator is working. But this is not the way to check because eAccelarator stores compiled PHP scripts in shared memory and executes code directly from it. It creates locks only for a short time, while searching for a compiled PHP script in the cache, so one script can be executed simultaneously by several engines. Files that can't fit in shared memory are cached on disk only.

If you look at the above image you can see that the shared memory is very close to being used up. At the point that this happens then it would be possible to look at the server disk and check for cache files. Next we'll take a look at installing another popular caching system, APC.

eAccelarator is a caching extension for PHP. It requires that PHP be run in FCGI mode. Rather than changing the name on the binary I create two of them in the same directory so switching back and forth is easy. But you can just rename your present php.cgi to php.fcgi as long as it has support for FCGI.

To turn on FastCGI at Dreamhost and use PHP as FastCGI you will first have to go into the control panel and set the domain properties for FastCGI.

Then use the following in your .htaccess file for that domain.

# PHP 5, Apache 1 and 2
Options +ExecCGI
AddHandler fastcgi-script fcg fcgi fpl
AddHandler php5-fastcgi .php
Action php5-fastcgi /cgi-bin/php5.fcgi


Happy Publishing!

Hiveminds's picture
This article brought to you by the Hiveminds Magazine - Staff. Contact us if you want to post an article or announcement anonymously
 
a Visitor posted on: Sat, 2007-01-06 14:11.

Just to let you know, in your script, you create a var named EACFEATURES for the user to edit, but it's never referenced later. :)

a Visitor posted on: Sat, 2007-01-06 15:34.

I've installed eAccelerator 0.9.5 with PHP 5.2... everything works fine the very first access to the page. Once the page is cached, I get the following in my error log:

FastCGI: comm with (dynamic) server "/PATH/TO/INSTALL/cgi-bin/php5.fcgi" aborted: (first read) idle timeout (60 sec)

FastCGI: incomplete headers (0 bytes) re
ceived from server "/PATH/TO/INSTALL/cgi-bin/php5.fcgi"

Any idea why FastCGI is puking now? If I disable eAccelerator, everything is a-ok... Seems as though once it's reading the compiled script from disk, things aren't looking too hot. Could I have possibly missed a compile flag from my php install?

Hiveminds posted on: Sat, 2007-01-06 15:47.

Hmm,

I see that twice in my Apache log. I don't have time to look at it now but I suspect that it has something to do with Dreamhost upgrading in the last few days.

I will keep an ey on it.

a Visitor posted on: Wed, 2007-01-10 09:42.

Thanks for the tutorial; it's exactly what I need. A couple of questions, though:

1. Do we need to have a custom PHP installed, like your first part of this series describes, or can we use Dreamhost's own PHP?

2. What changes to your process would be required if we needed to use PHP 4?

Thanks.

a Visitor posted on: Tue, 2007-02-20 20:34.

Everything went smoothly until:

./eaccelerator-install.sh: line 87: /home/xxx/php5//bin/phpize: No such file or directory

Now what?

a Visitor posted on: Wed, 2007-02-21 16:12.

You should have the compilers installed on the server. You must install autoconf, automake and libtools to do phpize.

a Visitor posted on: Mon, 2007-02-26 18:09.

Is there some kind of filter, geshi filter (probably) that is used in the syntax highlighting of the bash script?

a Visitor posted on: Tue, 2007-02-27 16:38.

The output is html made from Jedits code2html plugin. geshi was too resource intensive for my tastes.

a Visitor posted on: Sat, 2007-03-03 14:47.

I believe that eaccelerator has some kind of web interface, but I can't see any mention of it in the docs.

Do you know something about that?

Hiveminds posted on: Mon, 2007-03-05 08:43.

Yes, i have tried the PHP script for this you can download it from sourcefroge. But the script is not very well written (needs update) and does not work entirely in PHP 5.1.




Bitrix Site manager - fast to create, easy to manage CMS Comparison Matrix
Put Your Site Here Developer Links
Silverlight Silverlight Wordpress Content Management Systems Wordpress ASP.NET Adobe Flex
 

Newsletter

Get updates on Hiveminds services, articles and downloads by signing up for the newsletter.

Editor's choice

Some of the better articles, stories and tutorials found at Hiveminds.

Find more

Find more of Hiveminds articles, stories, tutorials and user comments by searching.




Picked links

Hand picked websites and articles from around the web that provide quality reading.