A combination of PHP and Java

Source: Internet
Author: User
The combination of PHP and Java
Recently, their small city has rolled up the e-commerce craze, e-commerce website companies are more and more, basically are Php+java mode. has been used in Java development, the whim also want to know how to achieve the combination of PHP and Java

Check the information on the Internet, generally implemented in 3 ways: WebService (SOAP), Quercus and Php-java Bridge

Myself in these days tried the front 2 ways. By the way, record the process.

I. WebService (SOAP)
1. First of all, of course, the release of a webservice service.
Or take the previous number calculation as an example
Package rong.service;

public class Calculateservice {

public in plus (int a) {
return a+1;
}
}

2. Publish the AAR to Tomcat Axis2 (refer to my Andorid connection webservice for specific methods)
3. Access via PHP (make sure php.ini is set up Php-soap)
$WSDL = "Http://localhost:8080/axis2/service/CalculateService";
$client =new soapclient ($WSDL);

Setting parameters
$params =array ("Param0" = "1");
Print results
Echo $response->return;
?>


Two, the second way Quercus

1. Use Quercus in fact just to download a resin file, because it already contains Quercus
You can directly call the Java class by simply placing the php file in the root of WebApps.
Like what:
Import rong.service.*;
$JAVAOBJ = new Calculateservice ();
Echo $JAVAOBJ->plus (1);
?>

2. To run PHP in tomcat, http://quercus.caucho.com/can download the Quercus.war file, throw it to Tomcat, and then follow the same method as above. There are several jar files required to run PHP in the war.

Summary:
According to the data consulted, webservice generally has a relatively poor performance, because in order to do cross-platform, XML needs DOM parsing, which consumes more memory. In the words of netizens: relatively simple, HTTP protocol penetrating ability, is very popular at present. But the downside is slow.

and Quercus words speed is good ah, on-line test Quercus php is 4 times times faster than the original, after all, is thrown to the servlet, is the first time the implementation of the full, and then good. The disadvantage is that it accounts for virtual machine resources.


Write the wrong place also ask the netizen to correct
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.