 |
PHP in GlassFish using Caucho Quercus
Posted by arungupta on August 24, 2007 at 06:07 AM | Comments (5)
Quercus is
Caucho Technology's 100% Java implementation of
PHP 5. Ludo
described the steps to deploy PHP web applications on
GlassFish. Caucho has released a new
version of Quercus since then. This blog
entry is an update to the
steps described earlier.
- First, PHP-enable GlassFish.
- Unjar
quercus-3.1.1.war and copy the JAR files in "
WEB-INF/lib"
directory to "GLASSFISH_HOME/domains/domain/lib" directory. That's it!
Although the original entry requires to copy the JARs in "GLASSFISH_HOME/lib/addons"
directory but that
didn't work.
- Create a PHP web application
- Create a new Web application project, lets say "
hellophp",
using NetBeans IDE and choose
GlassFish as the server.
- Replace the contents of "web.xml" with the following fragment:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<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>
</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>
</web-app>
This will declare PHP engine as the servlet.
- Add a new page "
index.php" in "Web pages"
folder. The contents of the page are:
<?php
echo "Hello World!";
phpinfo();
?>
This page prints "Hello World!" on the browser and some
configuration settings of PHP. The directory structure of the created project looks like:
META-INF/
META-INF/MANIFEST.MF
WEB-INF/
WEB-INF/classes/
WEB-INF/sun-web.xml
WEB-INF/web.xml
index.jsp
index.php
Notice, "index.jsp" is only a template
file to get started with JSPs and "sun-web.xml"
is GlassFish-specific deployment descriptor. These files are
not required for this PHP application although it does not hurt to leave
them in the webapp as well.
- Deploy the application by right-clicking on the project and selecting "
Deploy
Project". Your first PHP application in GlassFish is now deployed at
"http://localhost:8080/hellophp/index.php".
Now that you have verified that your GlassFish is ready to host PHP
applications, try the different applications that are described in
Ludo's blog.
Technorati:
php
glassfish
caucho
quercus
Bookmark blog post: del.icio.us Digg DZone Furl Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment
-
Worked straight out of the box, thank you! I also tried with Quercus 3.1.2 (I borrowed the Quercus jar's from a Resin 3.1.2 installation), works just fine.
Then it was time for some more EE stuff so I tried to have a php script send JMS messages to an MDB. Some notes:
- both the ConnectionFactory and the Queue have to be defined as Resource References in web.xml.
- you have to invalidate the JMSQueue object after sending the message, otherwise you end up with tons of JMS connections or problems because either glassfish or the broker won't allow you to create tons of connections. I just put
$queue = 0;
after sending the message and that seems to work.
Performance is good, approx. 100 msg/second using JMeter with 16 threads on an out-of-the box glassfish 58c with Java 1.6 on a 3GHz P4.
Next I'll try to send messages back to the php script and play around with some session beans.
Posted by: fvu on August 26, 2007 at 02:40 PM
-
The combination of Glassfish and Quercus is very interesting, so thanks for the update.
But where does NetBeans fit into the equation? As far as I can see, it's totally unrelated to the topic of this posting (unless you don't know how to create a webapp otherwise). Even worse, by using NetBeans for the instructions, you complicate the instructions by creating 2 unnecessary files, and then stating they're not necessary (Without explanation even. Does NetBeans always create 2 unnecessary files? Honesty, I have no idea). I have been meaning to take another look at NetBeans for some time now, but stuff like this really makes me reconsider.
On a similar note, "replace web.xml with the following" is ridiculous as well. As if I couldn't change the description or servlet name, or configure Quercus in addition to any other servlets. I guess I just don't like being talked to as if I was stupid.
Posted by: rpoellath on August 27, 2007 at 09:55 AM
-
fvu, thanks for the update on MDB.
rpoellath: Thanks for the feedback! The NetBeans IDE is used to generate a webapp only. I find it easier to generate the webapp structure using an IDE rather than creating the directories by hand.
"index.jsp" is the default file always generated by NetBeans IDE whenever you create a web app. A typical need for creating a webapp is to add JSPs to it. This index.jsp is only to get you started right away, it even contains a commented template code. "sun-web.xml" is created if GlassFish is chosen as the server. If you instead choose Tomcat as the server, then this file is not generated. I've updated the blog entry with this comment. However NetBeans 6 provides PHP editing which you might find helpful.
Lastly, this blog entry is targeted at all level of readers. It's great that you are familiar with some of the steps in which case you need to follow only the relevant ones.
I'd request to consider having a look at NetBeans. A variety of Flash demos for NetBeans are available at: http://www.netbeans.org/kb/articles/flash.html.
Posted by: arungupta on August 27, 2007 at 10:36 AM
-
How fast is the Java implementation of PHP that you mention above as opposed to (say) PHP thats part of Apache?
Posted by: bhatt246 on October 09, 2007 at 01:26 PM
-
bhatt246, This question needs to be asked on Caucho Quercus mailing lists (http://maillist.caucho.com/mailman/listinfo/quercus-interest).
Posted by: arungupta on October 10, 2007 at 10:28 PM
|