Is a very popular PHP scripting language.BEA Weblogic Server is built for Java application servers.Use PHP scripts to access all of the Java resource, this is not it? One way to accomplish this is to use PHP-Java bridge, through the bridge, Java and PHP can be run outside in their process, and through XML,communication.
Another interesting approach is the use of Quercus, which is a process in the same Java code running PHP implementation.It allows any Java resources for PHP scripts, including EJB, JMS Queues, database connection pool and POJO.
About Quercus
Quercus is a PHP 5 hundred percent pure Java.The role of the engine like PHP JSP.There is a PHP Servlet can accept all. Php file requests.It is responsible for analysis and interpretation of the page.
Quercus supports most standard PHP modules, and numerous extensions, including PDF, PDO, MySQL, and JSON.Access Quercus wiki get a complete list of supported extensions.
Quercus also verified some of the open source operating in their PHP applications, including MediaWiki, Drupal and Gallery 2.From here you can view the application and verified a complete list of supported versions.
Installation and operation
Download Quercus WAR file.WAR files will be unpacked into a temporary directory, for example, C: quercus ((assuming you are running Windows. In the Unix system, replace the appropriate path.) Next, extract the web application deployment to a runningWeblogic Server instance. Note: Due to restrictions on Quercus engine and can not be deployed without war file. Weblogic Studio can be deployed by Quercus. Dev2Dev the Workshop you can download a trial version of the page. Or, you can also console or command linedeployment.
To deploy from the command line, you first need to set the command-line environment.Then call the weblogic deployment process.
C: MyDomainbin> setDomainEnv
C: MyDomain> java weblogic.Deployer-user weblogic-password weblogic-url t3: / / localhost: 7001 /-deploy-source c: quercus everything is ready, you should be able to run.To test this, your web browser to: http://localhost:7001/quercus/.
Use Java objects (POJO)
As you can see, running pure Java solution is simple.Similarly, any type of Java objects to interact is also very simple.Listing 1 provides an example.
Listing 1. Javatest.php demonstrates the embedded Java within PHP access.
$ L = new Java ("java.util.ArrayList");
$ L-> add ($ buf = new Java ("java.lang.StringBuffer"));
$ Buf-> append ("100");
echo ($ l-> get (0) -> toString ()) + 2;
echo '
';
/ / Get instance of Java class java.lang.System in PHP
$ System = new Java ('java.lang.System');
/ / Demonstrate property access
echo 'Java version ='. $ system-> getProperty ('java.version'). '
';
/ / Java.util.Date example
$ Formatter = new Java ('java.text.SimpleDateFormat',
"EEEE, MMMM dd, yyyy 'at' h: mm: ss a zzzz");
echo $ formatter-> format (new Java ('java.util.Date'));
?>
Save the sample to the C: quercusjavatest.php.Then your web browser to http://localhost:7001/quercus/javatest.php.
As shown in the list, Java code is embedded into PHP.You will see the contents of the code similar to the following:
102
Java version = 1.5.0_06
Thursday, June 04, 2007 at 12:33:56 PM Pacific Daylight Time PHP class by calling the special Java, will create a variety of Java classes.This method is also applicable to instances of the Java is not the normal classes, such as java.lang.System.Access to Java object fields and method is similar to PHP to access fields and methods.From here for more details.
EJB usage
I have provided a sample EJB client and a PHP program.Download section contains a PHP script that contains the EAR and the Trader EJB client jar file.(EAR file also contains all the Java types of the source code.) To run the sample, please do the following:
Will ejbref.php on c: quercus.
Will TraderClient.jar on the c: quercusWEB-INFlib.
Files will be deployed to the target Trader.ear WebLogic Server instance.
The web browser to http://localhost:7001/quercus/ejbref.php
Listing 2 shows the source code ejbref.php.It loads a form, and send the user back to the request, will be on the instance of WebLogic Server EJB.
Listing 2. Ejbref.php
if (isSet ($ _POST ['ticker'])) {
$ Trader = getBean ();
if (isSet ($ _POST ['buy'])) {
$ Result = $ trader-> buy ($ _POST ['ticker'], ($ _POST ['shares'] + 0));
$ Action = 'bought';
}
else {
$ Result = $ trader-> sell ($ _POST ['ticker'], $ _POST ['shares'] + 0);
$ Action = 'sold';
}
$ Trader-> remove ();
print <<<__ html__
shares of $ action.
__HTML__;
}
else {
print <<<__ html__