Friday, 5 June 2009

Use Hazelcast library in PHP

If you want the power of Java in PHP, easily, the answer is Quercus / PHP. Quercus is a 100% implementation of PHP in Java. I have downloaed the GPL version of Resin, unzipped in C:\. The file to start the server is httpd.exe.

In "C:\resin-3.1.9\webapps\ROOT\WEB-INF" you will find "resin-web.xml", the configuration file of Resin. Copy the following text:

servlet-class="com.caucho.quercus.servlet.QuercusServlet">

Than create this file "hello-world.php" in "C:\resin-3.1.9\webapps\ROOT" and copy this text:

echo "Hello World";?>

Now you should be able to see the script executed: http://localhost:8080/hello-world.php

Go to the Hazelcast web site and download the zip. Inside the zip copy "hazelcast.jar" in "C:\resin-3.1.9\webapps\ROOT\WEB-INF\lib", create the lib directory if does not exist.

In "htest.php" you call the Hazelcast library, get an instance of a Map, a distributed Map! You put 3 new object into the map and than you print its property. To run this example you have to create the "Customer" class in PHP. In the same directory create "Customer.php" and copy this code: