php – Do you use Phing?-ThrowExceptions

Exception or error:

Does anyone use Phing to deploy PHP applications, and if so how do you use it? We currently have a hand-written “setup” script that we run whenever we deploy a new instance of our project. We just check out from SVN and run it. It sets some basic configuration variables, installs or reloads the database, and generates a v-host for the site instance.

I have often thought that maybe we should be using Phing. I haven’t used ant much, so I don’t have a real sense of what Phing is supposed to do other than script the copying of files from one place to another much as our setup script does. What are some more advanced uses that you can give examples of to help me understand why we would or would not want to integrate Phing into our process?

How to solve:

From Federico Cargnelutti’s blog post:

Features include file transformations (e.g. token
replacement, XSLT transformation,
Smarty template transformations), file
system operations, interactive build
support, SQL execution, CVS
operations, tools for creating PEAR
packages, and much more.

Of course you could write custom scripts for all of the above. However, using a specialized build tool like Phing gives you a number of benefits. You’ll be using a proven framework so instead of having to worry about setting up “infrastructure” you can focus on the code you need to write. Using Phing will also make it easier for when new members join your team, they’ll be able to understand what is going on if they’ve used Phing (or Ant, which is what Phing is based on) before.

Answer:

I moved from Ant to Phing ‘just because’ it’s PHP. I use it to export from different subversion repositories, copy stuff around, build different installation packages, etc all of that with a 20 line reusable xml file and a config file with project specific stuff. No way I could do it that fast with a custom script. I also plan to integrate api documentation generation and unit tests. Love it!

Answer:

The compelling answer for me is that phing understands PHP classpaths. Ant doesn’t. I don’t want to have an ant build.xml full of exec commands. I happen to be primarily a java programmer and still use phing. It’s the best tool for the job.

Answer:

We use phing to deploy SemanticScuttle:

  • generate zip archive for distribution
  • create PEAR package
  • upload zip to SourceForge
  • update the PEAR channel with the new package file
  • render reStructuredText documentation into html files and uploading them. Currently with exec but I’m on the way writing a separate task for it.

Uploading the zip file and the channel is done via rsync, which is unfortunately not supported by phing through a special task – but using exec is always possible and works nicely.

In the end, it saves a lot of time and we’re able to test, package and deploy our app with one single command (which gives us another point on the Joel Test). I would not want to live without it.

See the build.xml code.

Answer:

I don’t see any compelling reason to go with phing. I mean, should PHP programmers attempt a rewrite of Eclipse “just because” it might somehow be easier to write Eclipse plugins in PHP? I don’t think so.

Ant has better documentation, including some nice o’reilly books, and it’s well-established in the Java universe, so you avoid the problems of (1) “we haven’t copied feature X to phing yet” and (2) the risk of the phing project going dead. Here’s an article on configuring PHPUnit to work with ant and cruisecontrol: not that hard. And you get eclipse integration for free.

Good luck!

Leave a Reply

Your email address will not be published. Required fields are marked *