Subscribe via

Setting up a FreeBSD 6.2 Web Server: Optimizing PHP (Part 6)

This was by far the easiest step in my optimization process. To optimize PHP, I used the software called eAccelerator. Compared to all of the other steps, this one had the best ROI for me.

When a PHP script is executed, the PHP interpreter will spend some time interpreting the script then compile the interpretations into opcodes for execution. eAccelerator will precompile your PHP code into ready executable opcodes and manage that opcode cache for you. If your PHP script does not change, Apache will directly call the precompiled opcodes (saving interpretation and compilation time).

This is what I did to set it up:

1) Port install eAccelerator

cd /usr/ports/www/eaccelerator; make install clean

2) Inject these lines into /usr/local/etc/php.ini

; eAccelerator Stuff
extension="eaccelerator.so"
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"
eaccelerator.allowed_admin_path = "/usr/local/www/apache22/data"

3) Make cache directory writable

mkdir /tmp/eaccelerator
chmod 777 /tmp/eaccelerator

4) Restart Apache

/usr/local/etc/rc.d/apache22 restart

That’s it! This 10 minute optimization slashed my page generation time by 25%! But if that’s still not fast enough for you, I will show you how to do Proxy Caching next.