Web Apps with Tiger: Backups and Speed
Pages: 1, 2
Author's Note: Shortly before this article went to press, Apple released Xcode 2.2. Although I have not yet verified it myself, I've been told the update fixes the
php_version.h problem I workaround in the text. If your
php_version.h looks like the one I've included, you can continue installing eAccelerator as normal.
There's an insane number of factors involved when determining how "quick" your website is: hardware, network, software configuration, page and code design, user expectations, and more. We can score a number of Apache-related tips from its own performance tuning page, but there are dozens of articles with suggestions on writing better PHP. Instead of better coding, we're going to focus on faster PHP execution, regardless of the code's quality.
To do this, we're going to install a PHP module called eAccelerator. This module (and others like it) "increases the performance of PHP scripts by caching them in a compiled state, so that the overhead of compiling is almost completely eliminated." If you've used PHP caching systems before, eAccelerator is a continuation of Turck MMCache, no longer in development. Go ahead and grab the latest source code for eAccelerator (0.9.3 as of this writing) and save it to your desktop.
Before we can compile eAccelerator, however, we have to fix a minor bug within the Tiger Developer Tools (up to and including Xcode 2.2 Developer Preview 1). See, eAccelerator is going to be compiled with information from /usr/include/php/main/php_version.h, but that file suggests that we have PHP 4.3.10, when we actually have version 4.3.11. We'll need to change this to represent the correct information. First, we'll make a backup, and then twiddle the file's "write" bit:
cd /usr/include/php/main/morbus@:~ >
sudo cp php_version.h php_version.h.bakmorbus@:~ >
sudo chmod 644 php_version.h
Next, we'll need to change the file so that it looks like the below:
/* automatically generated by configure */ /* edit configure.in to change version number */ #define PHP_MAJOR_VERSION 4 #define PHP_MINOR_VERSION 3 #define PHP_RELEASE_VERSION 11 #define PHP_EXTRA_VERSION "" #define PHP_VERSION "4.3.11"
You'll need some sort of authenticating text editor (I will always prefer BBEdit) to save your changes. With those tweaks done, we can go ahead and compile eAccelerator. Move to your desktop, or wherever else you downloaded the source to, and run through the following:
tar xvzf eaccelerator-0.9.3.tar.gzmorbus@:~ >
cd eaccelerator-0.9.3morbus@:~ >
sudo /usr/bin/phpizemorbus@:~ >
./configure --enable-accelerator=shared --with-php-config=/usr/bin/php-configmorbus@:~ >
sudo make installInstalling shared extensions: /usr/lib/php/extensions/no-debug-non-zts-20020429/
These commands compile and install eAccelerator, but we still have to tell PHP that it should load and configure this new module. A few articles ago, we replaced our /etc/php.ini file with a more secure version, and we'll be going back to this file to make some eAccelerator-related changes. Open that file up in your favorite text editor, look for
extension_dir, and make the following change (you'll notice we're setting
extension_dir to the same value that our
make install reported above):
; Directory in which the loadable extensions (modules) reside. ; extension_dir = "./" extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20020429/"
Next, look for a block of configuration that starts with:
;;;;;;;;;;;;;;;;;;;;;; ; Dynamic Extensions ; ;;;;;;;;;;;;;;;;;;;;;;
And add the following somewhere after it:
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"
Save the file. Astute readers will notice
/tmp/eaccelerator as a value for the
eaccelerator.cache_dir parameter, and we'll need to manually create that directory and give it proper permissions:
mkdir /tmp/eaccelerator chmod 0777 /tmp/eaccelerator
Restart Apache (with
sudo apachectl restart) and reload the MediaWiki site we created last article. You'll know our new eAccelerator is working when
ls /tmp/eaccelerator/ returns a number of files of the following form--these are cached compilations of the various bits of PHP code that power MediaWiki:
eaccelerator-630188432.00949714 eaccelerator-630188432.38849714 eaccelerator-630188432.74949714
With a few more helper monkeys in our entourage, what's next? Our treasure map suggests "content management systems:" far more than blog software, but far less than handcoding everything yourself. Until then, don't hesitate to ask questions, wax poetic about future desires, or lament the errors.
Kevin Hemenway is the coauthor of Mac OS X Hacks, author of Spidering Hacks, and the alter ego of the pervasively strange Morbus Iff, creator of disobey.com, which bills itself as "content for the discontented."
Return to the Mac DevCenter
More info re: speeding up Drupal 4.6.3
2005-11-29 09:59:23 larrycummings [View]
2005-11-29 07:35:16 larrycummings [View]
Ugrading XCode to 2.2 did correct my PHP version number
2005-11-29 08:15:53 larrycummings [View]