38

I have built PHP based "health check" scripts for several projects in the past, but they were always custom-made for the occasion and not written for abstraction as an independent product. I would like to know whether such a solution exists.

What I meam by "health check" is a protected web page that functions much like a suite of unit tests, but on a more operational level, showing red/yellow/green statuses for things like

  • Are the cache directories writable?
  • Is the PHP version correct, are required extensions installed?
  • Is the database server reachable?
  • Do the necessary tables exist in the database?
  • Is there enough disk space available?
  • Is the site's front page reachable and renders fully ( = no PHP errors)?
  • Do the project's libraries' MD5 checksums match the original ones?
  • Does the front page's output pass the W3C validator?

Do you do this - or parts of it - in your applications and web sites?

Are there any standardized tools for this that bring along all the functionality to perform the tests (ideally as plugins), and just need to be configured accordingly?

I am talking about a lightweight solution that can run even on the tiniest of PHP-based web packages with no extensions and server access.

Is there, maybe, a way to set this up using one of the Unit Testing frameworks available for PHP (preferably PHPUnit)? If so, do you know any resources / tutorials outlining how?

Update: There does not seem to be a popular ready-made solution for this, otherwise, with more than 100 views, I'm sure there would have been some mention of it. Seeing as there's some initial interest in building such a tool as an open source project, please feel free to post what an ideal solution for you would look like, and what features it would have to have.

Pekka
  • 418,526
  • 129
  • 929
  • 1,058
  • A common tool for this with maybe an XML file as config would really be interesting. – Franz Mar 09 '10 at 01:34
  • 1
    @Franz yeah absolutely, with plugins for file operations (exists, is writable, md5), mySQL, and a web client to fetch and validate pages. Would be really worth building!.... – Pekka Mar 09 '10 at 01:40
  • What do you do if a health check shows a problem? Send yourself some email? – Mawg says reinstate Monica Mar 09 '10 at 01:55
  • @mawg not necessarily, a page called actively would be enough for many cases. Although the possibility of a hourly cron job would surely pretty quickly come up as a feature request. – Pekka Mar 09 '10 at 01:57
  • 1
    This sounds like a great open source project. Count me in. I would love to hear about best practices for this. I use CakePHP quite frequently too, so I could also see this as a test/vendor app for Cake as well. This sounds like a totally fun project! – Chuck Burgess Mar 09 '10 at 01:57
  • @cdburgess thanks for the feedback, good to know! I may actually be setting something up if no finished solution presents itself here. Will definitely let you know in that case. – Pekka Mar 09 '10 at 02:02
  • 1
    Oh yeah, I'd love to participate, too. – Franz Mar 09 '10 at 09:32
  • 1
    @Franz great! I will post any developments in here. I may even be putting a bounty on the question later to rake in a "wish list". – Pekka Mar 09 '10 at 10:20
  • As for posting a list: yours is already fairly complete and as that almost asks for a plugin architecture, it would be easy to add other aspects. – Franz Mar 09 '10 at 11:23
  • @Franz true. I will see whether I manage to whip up a proposal to discuss within the next few days. – Pekka Mar 09 '10 at 11:45

3 Answers3

3

Interesting question, but this is pretty broad. I haven't seen an unit testing tool yet which does all the backend, midend and frontend testing at once. I checked this list, but no one does it all. There is however one generic approach, xUnit (fully automated testing).

The major blockers are that backend testing is platform/DB specific and that midend testing is programming-language specific. And then yet to combine those limitations with frontend testing. The tool should then have to support almost all languages and platforms the world is aware of. I don't think such tool would ever be available in open source world. It's an utopia.

In theory it's indeed possible to have a testing framework with plugin capabilities, maybe based on the xUnit ideology, but one has yet to write/invent/opensource it. You? It's indeed a hole in the market.

At any way, for frontend unit testing (HTML/CSS/JS/forms) I would recommend Selenium, or if you have the money, TestComplete. I have seen it been used at IBM several years back, it was awesome to see it in action and the testers were very happy with this.

For midend unit testing (programming code, the business logic), just continue with the programming language specific unit testing tools like PHPUnit for PHP and JUnit for Java.

Regarding backend unit testing (DB, filesystem), I've used PGTap for PostgreSQL, but there are also generic DB tools available for this such as SQLUnit (which is however last updated almost 4 years back...). For the local disk file system conditions you'll have to grab platform specific scripting languages.

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
0

You can do all these with CruiseControl and phpUnderControl. But of course, you need to specify all those tasks you want to execute so your project pass all checks.

http://topecoders.blogspot.com/2010/04/how-to-install-cruisecontrol.html

With CruiseControl, you may add multiple tasks to be executed for every build of your project.

battcor
  • 41
  • 2
-1

Check out Nagios. It can be configured to poll URLs and scan for the presence/absence of strings, look for certain response codes, and quite a bit of other stuff. If you expose the stuff you want to look for in a URL, Nagios can do the rest.

@Franz Nagios support costs money, but the core monitoring software is free. It's kinda the Redhat model.

Trenton
  • 10,692
  • 9
  • 50
  • 57
  • Reeding it again, he didn't say that, but I believe something not commercial would be better (and this would only help with a part anyways) :-( – Franz Mar 09 '10 at 09:44
  • @trenton Cheers, I know of Nagios and while it more than matches the requirements, it is total overkill for what I have in mind. I am looking for something to drop onto an existing web site or app, able even to run on a small shared hosting package, which Nagios can't do. I edited the question to make that point much clearer. – Pekka Mar 09 '10 at 10:38