PEAR consists of literally hundreds of packages (libraries) that help you to build your PHP applications faster, less error-prone and more secure. Millions of web applications use and rely on the proper functioning of PEAR packages.
To ensure constant quality, many packages utilize phpt or PHPUnit tests that are run during development and before each release. They help us making sure new features or bug fixes do not break existing functionality.
One of hard to solve challenges is ensuring that a package's unit tests do not only run on the specific PHP version the developers have installed on their machines (which often is the latest and greatest, maybe not even released version from SVN), but to cover the whole range of supported PHP versions. This goal can be achieved in several ways:
- Test on different machines with another PHP version on each
- Test on different PHP versions on one machine
Solution number 1 requires either much hardware or at least quite some setup time for virtual machines. Besides that, running tests regularly on many different machines needs automated deployment tools - you won't ssh into the 15th machine manually, let alone setting up database servers and other software that might be required.
There is no single Linux distribution I know of that supports installing multiple versions of PHP beside each other - making solution number 2 similar daunting to setup and running as #1. The benefits above #1 are obvious: All software on one machine means easier deployment because the software to test needs to be setup only once. Software dependencies need to be installed only once. Executing the tests is easier if all versions of PHP are on this single machine, which means that the cross-version tests can be automated really easily.
A tool to solve all problems with the multiple-php-versions-on-one-machine solution is phpfarm. The best way to demonstrate its easiness is probably a shellshot:
$ cd /opt $ git clone git://git.code.sf.net/p/phpfarm/code phpfarm $ cd phpfarm/src $ ./compile 5.3.2 ... fetching sources from php.net ... configuring ... compiling ... installing ... fetching and setting up pyrus $ cd ../inst/bin $ ./php-5.3.2 --version PHP 5.3.2 (cli) (built: Mar 10 2010 18:08:27) (DEBUG) Copyright (c) 1997-2010 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies $ ./pyrus-5.3.2 --version Pyrus version 2.0.0a1 SHA-1: 2FDFB5E00A6D707437DBC047AAF9D115C6484D90 Using PEAR installation found at /home/cweiske/Dev/cvs/pear/phpfarm/inst/php-5.3.2/pear php pyrus.phar version 2.0.0a1.
That's it. With one single command, you can install each version of PHP you like, and you get pyrus, the next-generation PEAR installer for free! Let's try it:
$ pyrus-5.3.2 channel-discover pear.phpunit.de Discovery of channel pear.phpunit.de successful $ pyrus-5.3.2 install phpunit/phpunit ... Installed pear.phpunit.de/PHPUnit-3.4.11 $ pyrus-5.3.2 list-packages Listing installed packages [/home/cweiske/Dev/cvs/pear/phpfarm/inst/php-5.3.2/pear]: [channel pear.phpunit.de]: PHPUnit
phpfarm automatically sets up your php.ini with the values you desire. It sets your include_path. It lets you specify custom configuration options, per patch, minor or major PHP version - just have a look at the README.
Now everything is ready for you (and us PEAR developers!) to let the unit tests run on all the little PHP versions we want to. Did I tell you that phpfarm also installs php-cgi versions? My next blog entry will show you how to run dozens of PHP versions simultaneously in Apache.
If you have questions or suggestions about phpfarm, don't hesitate to ask on the pear-general mailing list (subscription info) or on the #pear IRC channel.
Happy testing!
Notes
My blog previously showed how to use phpfarm from /root/phpfarm/, which is total nonsense and should never be done. The best place for it is in /opt/phpfarm/.
Links
- There is an article about using multiple PHP versions on FreeBSD in case you are interested.
- Tutorial about using phpfarm on Ubuntu 10.04.