Accelerate PHP page performance with a cache/encoder
Nov 28, '03 08:51:00AM • Contributed by: blakers
Nov 28, '03 08:51:00AM • Contributed by: blakers
There are a number of commercial and open source encoding / caching / accelerating products availble for PHP webpage performance improvement. I've successfully installed Turck MMCache 2.4.6 (both a cache
and an encoder) to do the job. I've included the detailed benchmark results below, but I've seen roughly an 80% improvement with its addition.
Read the rest of the hint for the how-to on getting it up and running...
[robg adds: I haven't tested this one yet, mainly because it will mean re-building my PHP installatiion...]
A prerequisite is, of course, a working Apache and PHP install ... for reference, my server environment is:
Instructions (all run as root) are as follows:
REFERENCE: Turck MMCache Project @ SourceForge
To test the performance improvement, use ApacheBenchmark (/usr/sbin/ab) from a machine other than your server. Of course, you have to "point it" to a PHP page .... here I test against PhpPgAdmin's front page.
These numbers will vary with your page/environment, but should demonstrate the performance improvements. Here, e.g., note that "Requests per Second" improved by ~ 80% from 7.05 to 12.63 [#/sec] (mean)
Read the rest of the hint for the how-to on getting it up and running...
[robg adds: I haven't tested this one yet, mainly because it will mean re-building my PHP installatiion...]
A prerequisite is, of course, a working Apache and PHP install ... for reference, my server environment is:
- Apache/2.1.0-dev (Unix) with mod_perl/1.99_12-dev
- Perl/v5.8.2
- DAV/2
- PHP/4.3.4
- mod_ssl/2.1.0-dev
- OpenSSL/0.9.7c
./configure --disable-debug --prefix=/usr --enable-shared \
--disable-static --disable-dmalloc --with-tsrm-pthreads \
--with-config-file-path=/etc/php4 --sysconfdir=/etc/php4 \
--libdir=/System/Library --includedir=/usr/include \
--mandir=/usr/local/man --localstatedir=/var/php4 \
--enable-cli --with-pear=/System/Library/PHP \
--disable-cgi --enable-inline-optimization --with-layout=PHP \
--with-apxs2=/usr/sbin/apxs --with-expat-dir=/usr/local \
--with-pgsql=/usr/local/pgsql --without-mysql --with-openssl=/usr \
--with-db4=/usr --with-mcrypt --with-mhash \
--with-zlib --with-zlib-dir=/usr/lib --with-imap=/usr/local/imap \
--enable-mailparse --with-imap-ssl --with-png-dir=/usr/local/lib \
--with-jpeg-dir=/usr/local/lib --with-tiff-dir=/usr/local/lib \
--enable-ftp --with-freetype-dir=/usr/X11R6 --enable-magic-quotes \
--enable-calendar --enable-bcmath --with-java=/Library/Java/Home \
--enable-experimental-zts --with-gd --enable-shmop \
--enable-sockets --with-freetype-dir=/usr/X11R6 --with-ldap=/usr \
--with-kerberos=/usr --enable-exif --with-curl=/usr --enable-mbstring
NOTES:
PHP must be built with the DEBUG option OFF for the MMCache extension to load!! i.e.,
--disable-debug. I'm choosing to install MMCache as a Zend Extension, hence
the (required?) PHP option --enable-experimental-zts.
Instructions (all run as root) are as follows:
REFERENCE: Turck MMCache Project @ SourceForge
% cd /usr/ports
Download turck-mmcache-2.4.6.tar.gz and place it in /usr/ports.
% gnutar zxf turck-mmcache-2.4.6.tar.gz
% cd /usr/ports/turck-mmcache-2.4.6
% phpize
% ./configure \
--enable-mmcache=shared \
--with-php-config=/usr/bin/php-config
% make
% make install
% mkdir /tmp/mmcache
% chmod 0777 /tmp/mmcache
Install as Zend extension (NOTE: where the mmcache*.so is installed ... check it on your system!). PHP builds 'thread safe' as default, so I'm using the zend_extension_ts rather than the usual zend_extension. Check the path to your mmcache.so that's installed ...
mine's in /System -> Library -> extensions -> no-debug-zts-20020429 -> mmcache.so. If yours isn't, update your locate database with /usr/libexec/locate.updatedb, and then locate mmcache.so ... then change the first line's path to yours.
% vi /etc/php4/php.ini
(add this at the end of the file ...)
zend_extension_ts="/System/Library/extensions/no-debug-zts-20020429/mmcache.so"
mmcache.shm_size="16"
mmcache.cache_dir="/tmp/mmcache"
mmcache.enable="1"
mmcache.optimizer="1"
mmcache.check_mtime="1"
mmcache.debug="0"
mmcache.filter=""
mmcache.shm_max="0"
mmcache.shm_ttl="0"
mmcache.shm_prune_period="0"
mmcache.shm_only="0"
mmcache.compress="1"
Stop and start your web server ...
% apachectl stop
% apachectl start
After Apache restarts, check your phpinfo() to make sure its output shows:
"This program makes use of the Zend Scripting Language Engine:
Zend Engine v1.3.0, Copyright (c) 1998-2003 Zend Technologies
with Turck MMCache v2.4.6, Copyright (c) 2002-2003 TurckSoft,
St. Petersburg, by Dmitry Stogov"
TEST:To test the performance improvement, use ApacheBenchmark (/usr/sbin/ab) from a machine other than your server. Of course, you have to "point it" to a PHP page .... here I test against PhpPgAdmin's front page.
% ab -n200 -c1 -dS http://myserver.mydomain.com/admin/phppgadmin31/index.php
RESULTS:These numbers will vary with your page/environment, but should demonstrate the performance improvements. Here, e.g., note that "Requests per Second" improved by ~ 80% from 7.05 to 12.63 [#/sec] (mean)
Server Software: Apache/2.1.0-dev
Server Hostname: myserver.mydomain.com
Server Port: 80
Document Path: /admin/phppgadmin31/index.php
Document Length: 6890 bytes
Concurrency Level: 1
With Turck "ON"
Time taken for tests: 15.835 seconds
Complete requests: 200
Failed requests: 0
Broken pipe errors: 0
Total transferred: 1463000 bytes
HTML transferred: 1378000 bytes
Requests per second: 12.63 [#/sec] (mean)
Time per request: 79.18 [ms] (mean)
Time per request: 79.18 [ms] (mean, across all concurrent requests)
Transfer rate: 92.39 [Kbytes/sec] received
Connnection Times (ms)
min avg max
Connect: 0 1 28
Processing: 55 78 1502
Total: 55 79 1502
With Turck "OFF" [commented out in php.ini]
Time taken for tests: 28.364 seconds
Complete requests: 200
Failed requests: 0
Broken pipe errors: 0
Total transferred: 1469600 bytes
HTML transferred: 1378000 bytes
Requests per second: 7.05 [#/sec] (mean)
Time per request: 141.82 [ms] (mean)
Time per request: 141.82 [ms] (mean, across all concurrent requests)
Transfer rate: 51.81 [Kbytes/sec] received
Connnection Times (ms)
min avg max
Connect: 0 1 57
Processing: 94 141 3191
Total: 94 141 3191
Finally, note that MMCache can be managed through an included web interface script, mmcache.php, and that there's a third party Encoder GUI, phpcoder-1.3 available.
•
[13,337 views]
