Step 3: Create com.caucho.quercus.QuercusModule and place it in $webApp/WEB-INF/classes/META-INF/services

com.caucho.quercus.QuercusModule

example.HelloModule

Step 4: Create hello.php and place it in webapps/ROOT

hello.php

<?php echo hello_test("World") ?>

In your favorite browser, type:

http://localhost:8080/hello.php

You should see:

Hello, World

Advanced Users

The first argument of a Java function may be the Env. The Env provides access to Quercus resources like printing to the browser and retrieving a PHP ini value. For the API of Env, refer to the Quercus javadoc.

Now hello_test will print "inside HelloModule hello_test()" to the browser before returning.

Java Function Arguments/Return Marshaling

Quercus does marshaling to and from Quercus Values and Java objects. If a Java function requires a String, Quercus will automatically convert the internal Quercus StringValue to a String. If a Java function returns an int, Quercus will create a Quercus LongValue for it.

For other Java Objects like java.util.Date that are returned to PHP, Quercus puts them into wrappers to expose their public methods and members to the PHP script. Java Collection, List, and Map instances have the additional ability to be used within a PHP script like any other PHP array.

Conclusion

It is fairly straight forward to create your own modules callable from
within a Quercus/PHP page. The above tutorial takes through the steps
to create the simple hello world application (without needing
to "jar-up" your files).

If you want to change your module in any way, all you have to do is
resave the ".java" file in the classes\example directory, and Resin
will recompile it for you.

You do not need to restart your web app or Resin. It's just that simple.

Cloud-optimized Resin Server is a Java EE certified Java Application Server, and Web Server, and Distributed Cache Server (Memcached).Leading companies worldwide with demand for reliability and high performance web applications including SalesForce.com, CNET, DZone and many more are powered by Resin.