Improving Drupal's Performance with Quercus and Jetty (PHP in Java)

Quercus is Caucho Technology's 100% Java implementation of PHP 5 released under the Open Source GPL license. Quercus comes with many PHP modules and extensions like PDF, PDO, MySQL, and JSON. Quercus allows for tight integration of Java services with PHP scripts, so using PHP with JMS or Grails is a quick and painless endeavor. (Excerpted from Quercus)

PHP scripts are compiled to Java code and run in Java Virtual Machine, it gives better performance to PHP in Apache/PHP event with APC (Alternative PHP Cache) enabled. See Resin backed PHP drives 4x performance improvements for Drupal.

I tried to install Jetty, Quercus, MySQL to run Drupal in Java Virtual Machine. Quercus still has errors with multi-bytes charset so please do not use it if you are running PHP/Drupal websites with unicode encoding.

Here is some notes when i get Drupal to run with Quercus on my VPS/CentOS.

Make sure you installed Java or Install it by following command

yum install java

Install Jetty

Jetty is a 100% pure Java-based HTTP server and servlet container. Jetty is a free and open source project under the Apache 2.0 License. Jetty is used by several other popular projects including the JBoss and Geronimo application servers. Jetty deployment focuses on creating a simple, efficient, embeddable and pluggable web server. Jetty's small size makes it suitable for providing web services in an embedded Java application.

You need get lastest version of Jetty from Codehaus then install it.

$ wget http://dist.codehaus.org/jetty/jetty-6.1.16/jetty-6.1.16.zip
$ unzip jetty-6.1.16.zip
$ cp -R jetty-6.1.16 /opt/
$ cd /opt

Running Jetty

Running jetty is as simple as going to your jetty installation directory and typing:
$ cd /opt/jetty-6.1.16
$ java -jar start.jar etc/jetty.xml

This will start jetty and deploy a demo application available at:
http://localhost:8080/test

That’s it. Now stop Jetty with cntrl-c in the same terminal window as you started it.

Installing Quercus

$ wget -P ~/quercus http://quercus.caucho.com/download/quercus-3.2.1.war
$ jar xf ~/quercus/quercus-3.2.1.war

Unpack the WAR file and copy all the jars to Jetty’s global library directory:
$ cp ~/quercus/WEB-INF/lib/* /opt/jetty-6.1.16/lib

Configuring Jetty

WEB-INF/web.xml

Add the following between the web-app tags:

<description>Caucho Technology's PHP Implementation, Running on GlassFish Java EE 5</description>
<servlet>
<servlet-name>Quercus Servlet</servlet-name>
<servlet-class>com.caucho.quercus.servlet.QuercusServlet</servlet-class>
<init-param>
<param-name>database</param-name>
<param-value>jdbc/drupal</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Quercus Servlet</servlet-name>
<url-pattern>*.php</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.php</welcome-file>
</welcome-file-list>
<resource-ref>
<description>MySQL JDBC DataSource </description>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>

WEB-INF/jetty-web.xml

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
<New id="drupal" class="org.mortbay.jetty.plus.naming.Resource">
<Arg>jdbc/drupal</Arg>
<Arg>
<New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
<Set name="Url">jdbc:mysql://localhost:3306/drupal</Set>
<Set name="User">dbuser</Set>
<Set name="Password">dbpassword</Set>
</New>
</Arg>
</New>
</Configure>

Change in DATABASE.MYSQL.INC

function db_connect($url) {
$quercus_url = substr($url,strpos($url,"://")+3); // before parse_url() call
...
// $connection = @mysql_connect($url['host'], $url['user'], $url['pass'], TRUE, 2);
$connection = mysql_connect($quercus_url); // replaces call above
...
}

SETTINGS.PHP

$db_url = 'mysql://jdbc/drupal'; // The mysql:// prefix is needed otherwise Drupal reports a database initialization error

Start Jetty agai

$ java -jar start.jar etc/jetty.xml

Now, you can test your work at http://localhost:8080/ 

Comments

Re: Improving Drupal's Performance with Quercus and Jetty ...

Interesting way to run Drupal on JVM (php)
I would try to test it with Firebird database connection just to see how it works

Re: Improving Drupal's Performance with Quercus and Jetty ...

Believe it or ed hardy can pep up the sizzling summer too. Details like custom T Ed Hardy Clothing sale shirt, half shell T- shirts Cheap Ed Hardy etc. Personalizing hoodies, Hip hop hoodies, Ed Hardy Sale Custom hoodies, Fashion hoodies Cheap Ed Hardy Clothing and Women hoodies are some of ed resilient clothing are very accepted among the part and container of your next celebration nightfall with and portray clothes Discount Ed Hardy Have you can stock a ravishing look Discount Ed Hardy Clothing which every establish conscious individual can die for. Depending befo