Tuesday, December 8, 2009

PHP in JAVA using quercus resin server in windows

Quercus is Caucho Technology's fast, open-source, 100% Java implementation of the PHP language

Quercus is written for Resin, a Java application server.

If your using resin server then you can able to call java module from the php page . but here I am showing running of php file with the tomcat server using java compiler
The interesting thing is you can import java libraries or module from php page.
Follow the setps to install the quercus (resin server)

Step1.
Download the resin server installation package from the this page(http://www.caucho.com/download/)

Step2.
Unzip downloaded file and put it inside the your c drive

Step3.
dont forgot to install JDk(1.5 or >) and set the environment path for the same

Step4.
when you open resin main folder(\resin-pro-3.1.9) you can see http file click on it and that will start your resin server
NOTE:-in case if you’re not able to run the resin server
Step1.you can see the setup file inside the main resin folder run that folder it will ask you some configuration

Step2.click on the apache server option and give the root path to the apache where you have installed apache so that it can able to access the apache http.conf file form there.

Step3.then press apply and then start http file it should start your resin server now

Step4. In worst case you can able to start the resin sever from the command prompt eit the following command . change the path in to your resin main folder and then run this command” cd:\resin>java –jar lib/resin.jar start” .

Step5.now open browser and type http://localhost:8080/ you should see the default page of the resin server if that comes your installation is correct. then proceed further

Step 6. Inside \resin-pro-3.1.9\webapps\ROOT\WEB-INF folder create web.xml with the following code


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




Step7.
inside \resin-pro-3.1.9\webapps\ROOT\WEB-INF\classes\example create java class file with the

HelloWorld .java

package example;

import com.caucho.quercus.module.AbstractQuercusModule;

public class HelloWorld extends AbstractQuercusModule {
/*
** Notice the careful use of the naming
** convention hello_test. This is done
** in order to prevent name collisions
** among different libraries.
*/
public String hello_test(String name)
{
return "Hello, " + name;
}
}

Step8.
inside \resin-pro-3.1.9\webapps\ROOT\WEB-INF\classes\META-INF\services create the following file with name “com.caucho.quercus.QuercusModule” put the content

example.Helloworld

step9.
Now inside \resin-pro-3.1.9\webapps\ROOT create the php page which calls the java module with name hello_world.php

echo "your module data comes here “."
";
echo hello_test("World")."
";

?>

Step 10.
Now run the hello_world.php from the URL as
http://localhost:8080/hello_world.php

You should see “your module data comes here
hello world”

No comments: