Skip to Navigation

Life with Quercus: PHP Via Java

Printer-friendly version

There has been a lot of (virtual) ink spilled over HipHop, Facebook's new PHP-to-C compiler; but a similar approach has flown a little more under the radar.  I'm talking about Quercus, a PHP interpreter/compiler written in Java by Caucho, the makers of the Resin app server.

Quercus is a servlet that can be deployed in any J2SE/J2EE servlet container — Resin, Tomcat, JBoss, WebSphere, etc. — and can run PHP applications deployed in the same webapp. Of course the question is why would you use Quercus when you can use Zend's PHP interpreter?

Unlike HipHop where the biggest reason to use it is performance, the case for Quercus is slightly more nuanced. Quercus has more capabilities than HipHop out of the box; for instance you can drop Drupal, WordPress, Joomla, MediaWiki, Gallery2 and more in Quercus and they run. Need to use eval (I'm looking at you, Drupal)? No problem.

Similarly, unlike HipHop which contains a built-in web server, Quercus is a servlet which provides you more  options on how you run it.  And because we're running on Java we have access to all the tasty goodies that people have written for it. Need asynchronous messaging? Love JMS?  Multi-node caching? Terracotta and Ehcache rocks — interestingly enough someone already did this with Drupal. The list goes on and on...Apache Axis is great for web services, GraniteDS does almost as much as Adobe LifeCycle to connect with Flex.

When you look at the documentation for Quercus, they talk about performance being at least comparable to Apache/PHP, and they're mostly correct. Deploying a fairly intensive community Drupal site (OG, Spaces, lots of Views) on Resin 4 and testing with Apache Bench (AB) on a workstation puts Resin running only slightly slower than Apache, at least up to 50 concurrent users.

There is some room to grow on the Resin side as it was running pure Java, no JNI, and anecdotal testing indicates that this provides some 10-12 percent performance benefit. So out of the box this would put Resin processing requests at about the same speed as Apache.

We were testing the community version of Resin and Quercus, the Professional version has the ability to compile PHP to Java using the same sort of static analysis techniques used by HipHop and, at least according to benchmarks published by Caucho (PDF), show an increase in performace of Drupal, WordPress, and other common PHP applications, ranging from ~17 percent in phpBB to almost 110 percent for WordPress. 

So, what's not to love, right? We can take existing PHP applications, move them over painlessly and get both increased performance and capability.

Sadly, things are not that clear-cut. Going back to the example below of the 50 concurrent connections. While performance was roughly equivalent, the effect on system resources was not, Resin used considerably more memory than the comparable test on Apache. Another issue is lack of sophisticated URL rewriting on some servlet containers. Resin supports enough of the functionality of mod_rewrite to make Drupal work, but others do not. Getting Drupal clean URLs in Tomcat, for example, is difficult. Other uses of mod_rewrite may not work at all without significant effort.

And perhaps the biggest downside for Quercus is inherent in what it is. It's Java. For organizations that have made a significant investment in PHP the code is not all there is. You have systems tuned for the LAMP stack. You have system administrators that are knowledgable and experienced in maintaining those systems. You build solutions that use PHP, and while the additional functionality of Java is nice, what do you do with it?  But like HipHop, the very existance of Quercus is encouraging.  While I don't have a project right now targeting Quercus, and I may never, the fact that companies like Facebook and Caucho are innovating and adding new options, new features makes this an exciting time.

Comments

PHP + JAVA = future technological trend

Hi,

I agree, that porting of PHP with huge number of extensions into JAVA is tremendous task. As for now, Caucho supports only very few extensions (APC, GD, JSON). This is biggest limitation from my point of view. If they would like to support massive usage, they should test for more PHP5 killer apps (Yii framework, CakePHP, SimpleTest/PHPUnit, ZF etc).

I disagree that merging JAVA + PHP technology brings no benefits. Of course it does!
I have been working with PHP since last 7 years and even now - with PHP5 - we still have great problems to figure out effective solution for dynamic generation of signed PDF documents, with web services, XSLT transformations, manipulating large XML objects, encryption algorhytms etc. Java does many things in easy way - its like merging intellectual work of two huge communities.

Java is simply heavy industrial technology and if you try to implement payment gateway, you will always get API for JAVA and less often for PHP:-( So for PHP professionals, working for large clients, co-working both technologies is definitely beneficial.

Regards
Lubos

I agree

William Hurley's picture

I've enjoyed working with both PHP and Java -- though it takes some getting used to working with some of the Apache projects like JSF and Cocoon -- and I think they have a large amount of synergy. There are a lot of things that become possible when you have a persistent middle-tier, something that Apache / PHP is unlikely to ever have, and I think I mention some of those like messaging, distributed caching, push notification like Comet, etc. I think the main obstacle is similar to why Facebook is still using PHP, why they created HipHop: prior investment. Time and energy spent going in a new direction is not spent in advancing your product or service. I guess put me in the cautiously optimistic camp. I'd love to see it, but there's nothing I can do to advance it right now other than read and talk about it.

Panel Modules Under Quercus

I have tried running Quercus as a web app under Jetty and had no problems at all getting it going. I then migrated my Drupal 6.17 site to run under it and it appeared all was working OK.

I then discovered that there are problems using the Panel Module where content does not appear when running under Quercus.

Performance seems at least equal to Apache/PHP combo and if I can get the Panels Module problem sorted out, I'll probably use it as my deployment platform

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Mollom CAPTCHA (play audio CAPTCHA)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.