Can I finally have the best of both PHP and Java?

I regularly switch between PHP and Java projects, and there are elements I prefer from each one. Conversely, there are elements that can drive me mad.

If you're developing a large PHP application, then these days it's certainly possible to build something that's well structured, object-oriented and performant.  On the other hand, it's harder to refactor, and the process involves generally more work than the same 'back-end' code would in Java in my opinion, mainly due to weak typing and poor library support (PHP XML support sucks, for example). How many readers have tried to produce PDF documents?

Java on the other hand, is ideal for back end work, but in my opinion strongly typed languages and HTML don't mix that well. Front end work is also typically the domain of designers, and designers maybe haven't taken to JSP in the way that Sun would like.  One of the advantages of PHP is the rapid edit-deploy-test cycle, and if designers find it easier to work with PHP, why not let them?

I'm sure that many people would disagree, but we're not talking about one language fits all here.  Sometimes there are compelling reasons to mix both PHP and Java - maybe for some networking feature that Java offers, or application server clustering, or the need to use a legacy PHP application in a new Java project.

Enter Quercus

I came across this the other day.  Quercus is a Java implementation of PHP, by the creators of the Resin application server.  I downloaded Resin and managed to write a Java class and a PHP script that used it within about 10 minutes. 

They claim a 400% speed improvement over plain mod_php, and performance on a par with accelerator-improved PHP. What really attracts me to the implementation though, is that it's really easy to wrap Java code and use the results directly in PHP code.  So, you can use Hibernate to back your PHP model code, Apache FOP to generate PDF documents, JGroups to provide caching, load balancing or data distribution, etc., etc.

If you're hitting the limits of PHP or want to use some existing PHP code like Drupal (yuk), PhpBB, etc., then it's worth a look.


© eCreate Web Services Limited, 2008