Integration of PHP and Java Web Development

Source: Internet
Author: User
Tags php compiler soap client web hosting
Preface PHP provides an embedded statement for HTML, which is easy to configure and has high efficiency when used with the Apache Web Hosting Server. Preface PHP is a simple syntax script language and can be used as an embedded HTML language. It is easy to set up and efficient with Apache Web server. Java is the best show object for commercial purposes.

Preface PHP provides an embedded statement for HTML, which is easy to configure and has high efficiency when used with the Apache Web Hosting Server. Preface PHP is a simple syntax script language and can be used as an embedded HTML language. It is easy to set up and efficient with Apache Web server. Java is the best show object for commercial purposes.

PrefaceFor example, PHP can be used as an embedded Statement of HTML, and it is easy to set up and efficient to work with the Apache Web Hosting Server.PrefacePHP is a simple syntax script language and can be used as an embedded HTML language. It is easy to set and efficient with Apache Web server. Java is a showcase for commercial purposes. It has many useful programs and many Web application development frameworks ). Java is an excellent object-oriented language for commercial purposes. It has many useful libraries and many Web application development frameworks ). Compared with other PHP and Java, PHP's commercial application programs are lacking, while Java's coding and development environments are set to programming languages. Comparing PHP and Java, PHP lacks commercial application libraries, and Java syntax and development environment settings are more complex. Therefore, Web developers should not accept the opinions of PHP or Java, but should adapt to the time limit, which is the combination of the two programming languages of PHP and Java, in order to develop Web applications more efficiently. Therefore, Web developers should review the current situation and combine the advantages of PHP and Java to develop Web applications more efficiently. This article will introduce three different PHP and Java integrated development technologies, hoping to provide an integrated testing environment for building PHP and Java Web development. This article will introduce three different Integrated Development Technologies for PHP and Java, hoping to provide reference for building an integrated environment for PHP and Java Web development.

Three Web development integration technologies for PHP and Java
  
Currently, known Web development and integration technologies of PHP and Java can be divided into three types: SOAP (Simple Object Access Protocol), Quercus, PHP/Java Bridge, these technologies allow PHP and Java to use each other's programs when developing Web applications.Integration of three PHP and Java Web Development Technologies

Currently, the integration of PHP and Java Web development technology can be divided into three types: SOAP (Simple Object Access Protocol), Quercus, and PHP/Java Bridge, these technologies allow PHP and Java to use each other's libraries when developing Web applications. This article focuses on how to use Java program libraries in PHP programs and how to configure suites such as SOAP, Querus, PHP, and Java Bridge. This article focuses on how to use Java libraries in PHP programs and how to configure suites such as SOAP, Querus and PHP/Java Bridge.

The Java program example used in this article is shown in List-1: the Java library example used in this article is shown in List-1:

List-1 HelloService. java List-1 HelloService. java

The following describes how to integrate PHP with SOAP, Querus, and PHP/Java Bridge Technology to call echoHello ("Jason "), and get the response result of "Java say hello to Jason. The following describes how to integrate PHP with SOAP, Querus, and PHP/Java Bridge Technology to call echoHello ("Jason") and get the execution result of "Java say hello to Jason.

1. SOAP (Simple Object Access Protocol) 1. SOAP (Simple Object Access Protocol)

SOAP is developed by IBM, Microsoft, and other companies. It is used as a benchmark for distributed object technologies. SOAP is a protocol developed by IBM, Microsoft, and other companies. It is recommended by W3C to implement distributed object technology. SOAP provides a set of machines that use XML to package program calls, dynamic data transfer, and response messages. With the features of XML plain text, attackers can use HTTP, HTTPS, SMTP, and other communication channels to access enterprise-level fire protection channels, compared with distributed object technologies such as CORBA, Java RMI, and DCOM that provide data in binary format, SOAP has the following features. SOAP provides a set of mechanisms for packaging program calls, parameter transmission, and message return in XML. With the characteristics of XML plain text, it can pass through the enterprise's firewall through communication channels such as HTTP, HTTPS, and SMTP, compared with the distributed object technology protocols that transmit data in proprietary binary formats, such as CORBA, Java RMI, and DCOM, SOAP has features unrelated to programming languages, platforms, and hardware.

Apache Axis2 is the most commonly used SOAP suite in Java, and PHP is the php-soap extension module. Apache Axis2 is the most commonly used SOAP suite in Java, and PHP is the php-soap extension module. The following describes how to integrate PHP and Java through the two SOAP suites. The following describes how to integrate PHP and Java through the two SOAP suites.

(1) pre-jobs: Server guard PHP> = version 5.0, JDK> = version 1.4, and Tomcat. (1) pre-job: install PHP> = 5.0, JDK> = 1.4, and Tomcat.

(2) Use Apache Axis2 to set List-1 HelloService. java program deployment to SOAP Web Services (2) use Apache Axis2 to List-1 HelloService. deploy the java library into SOAP Web Services

1. install Apache Axis2 1. install Apache Axis2

First go to the latest WAR (Web Archive) Distribution-axis2.war under the beginning of the Apache Axis2 website. First download the latest WAR (Web Archive) Distribution-axis2.war from the Apache Axis2 website homepage. Set unpackWARs in Tomcat server configuration to True, and then route axis2.war to Tomcat's webapps. Set unpackWARs in Tomcat server configuration to True, and then copy axis2.war to the webapps directory of Tomcat. Restart Tomcat. If you have asked http: // localhost: /Axis2 can see that Axis2 is welcome to complete the Apache Axis2 security. Restart Tomcat. If you access http: // localhost: /Axis2 you can see the Axis2 welcome page to complete the installation of Apache Axis2. Where It is the Tomcat Network Service port, generally 8080. Where It is the network service port of Tomcat, generally 8080.

2. Deploy the HelloService Service 2. Deploy the HelloService Service

(1) Write service. xml to describe service deployment information (1) Write service. xml to describe service deployment information

The service deployment information of HelloService. java is shown in List-2. The service deployment information of HelloService. java is shown in List-2. The name of the service depends on the name of the service. The service name attribute defines the service name. Apache Axis2 uses the service name to construct the server's End Point address, such as http: // localhost: /Axis2/services/ . Apache Axis2 uses the service name to create the service endpoint address, such as http: // localhost: /Axis2/services/ . Therefore, the end point of the HelloService service is http: // localhost: /Axis2/services/HelloService. Therefore, the endpoint address of the HelloService service is http: // localhost: /Axis2/services/HelloService. The ServiceClass category number specifies the type of service response. The ServiceClass parameter specifies the service category. Each Element defines the configuration of an operation in the service. Each Element defines the configuration of an operation in the service. The name attribute of should be set to the name of the method in the server response class. The name attribute of should be set to the name of the method in the corresponding category of the service. The messageReceiver element defines the message receiver that processes this operation. The messageReceiver element defines the Message Receiver used to process this operation.

List-2 services. xml List-2 services. xml

(2) package the service package into Axis Archive (2) package the service into Axis Archive

To deploy Apache Axis2, you must first package it into Axis Archive (. aar. The Apache Axis2 service must be packaged into Axis Archive (. aar) before it can be deployed. The format of Axis Archive (. aar) is the same as that of the jar file (created using jar or zip), and the content contains the types of service applications and services. xml. The format of Axis Archive (. aar) is the same as that of the jar file (created using jar or zip). It contains the category of the service and services. xml. The internal structure of the aar file of HelloService is shown in List-3. The internal structure of the aar file of HelloService is shown in List-3:

List-3 Internal Structure of HelloService. aar List-3 HelloService. aar

(3) complete service deployment (3) complete service deployment

Deploying a server in Apache Axis2 is simple. You only need to route. aar to/webapps/axis2/WEB-INF/services/Under the Tomcat project. Deploying services in Apache Axis2 is quite simple. You just need to copy. aar to/webapps/axis2/WEB-INF/services/Under the Tomcat directory to complete the deployment.

(3) use the php-soap extension module to enable PHP worker to use HelloService Service (3) use the php-soap extension module to enable PHP to call the HelloService service.

1. Configure the php-soap extension modulo. 1. Load and set the php-soap extension modulo.

(1) load the plugin into the php-soap extension module (1) load the php-soap extension module

Find the extension mode settings in php. ini and add a line of tokens to automatically import the php-soap extension mode. Find the extension module settings in php. ini and add a line of code to automatically load the php-soap extension module. On Windows, this line of arguments is: "extension = php_soap.dll"; on UNIX: "extension = php_soap.so 」. On Windows, this line of code is: "extension = php_soap.dll"; on UNIX: "extension = php_soap.so 」. Define and set extension_dir to point to the object that contains the php-soap extension model. Define and set extension_dir to point to the directory containing the php-soap extension module. If you need to restart the original program, add the -- enable-soap option in the configure command, and then restart the program. To re-compile the original code, add the -- enable-soap option in the configure command and re-compile the code.

(2) set the php-soap extension module (2) set the php-soap extension module

Add the following code in php. ini to complete the settings of the php-soap extension mode: Add the following code in php. ini to complete the settings of the php-soap extension module:

[Soap] [Soap]
Soap. wsdl_cache_enabled = 0 Soap. wsdl_cache_enabled = 0
Soap. wsdl_cache_dir = "/tmp" Soap. wsdl_cache_dir = "/tmp"
Soap. wsdl_cache_ttl = 86400 Soap. wsdl_cache_ttl = 86400

2. Create the SOAP client of PHP 2. Write the SOAP client of PHP

As shown in List-4, sayHello1.php first retrieves the WSDL file of the HelloService Service (which is composed of two kernel services of Apache axis2. create a SOAP client, set param0 to Jason, and then call the echoHello function of HelloService, the final result of the returned result is: "Java say hello to Jason". The running process of zookeeper is shown in step 1. As shown in List-4, sayHello1.php first reads the WSDL file of the HelloService service. (generated in xml) to create the SOAP client, set the parameter param0 to Jason, call the echoHello function of the HelloService service, and obtain the result of parallel output: "Java say hello to Jason ", the detailed operation process is shown in.

List-4 sayHello1.php List-4 sayHello1.php

Example 1 use SOAP to integrate PHP and Java; example 1 use SOAP to integrate PHP and Java

Ii. Quercus Ii. Quercus

Quercus is the PHP 5 engine (required JDK 100%) developed by Caucho Technology for resin application server in Java 1.5 ). Quercus is a Java-based PHP 5 engine (required JDK 100%) developed by Caucho Technology for resin application server 1.5 ). Quercus can allow PHP programs to publish lines on the JVM. The following describes how to integrate PHP and Java using Quercus with resin. Quercus allows PHP programs to run on JVM. The following describes how to integrate PHP and Java using Quercus with resin.

(1) pre-job: Install JDK> = 1.5. (1) pre-job: Install JDK> = 1.5.

(2) Installing resin application server and Quercus (2) Installing resin application server and Quercus

First, go to the zip file of the resin application server under the first release of Caucho Technology (http://www.caucho.com/), and then parse it to a specific project $ RESIN_HOME, for example, c:/resin in a windows environment. First download the zip file of resin application server (containing Quercus) on the home page of Caucho Technology, and decompress it to a directory $ RESIN_HOME, such as c in windows: /resin. When using httpd.exe under resin_home, use the zookeeper to restore http: // localhost: 8080/. If you can see the success surface of successfully merged rows, it indicates that resin application server and querocus have successfully been installed. Start httpd.exe under restore resin_homeand use a browser to connect to http: // localhost: 8080/. If you can see the successful execution screen, it indicates that resin application server and quercuz have been successfully installed.

Put List-1 HelloService. java under $ RESIN_HOME/webapps/ROOT/WEB-INF/classes/hello/contents. Put List-1 HelloService. java in the $ RESIN_HOME/webapps/ROOT/WEB-INF/classes/hello/directory. When HelloService. java is used, it is automatically converted into a class file. When HelloService. java is called, it is automatically compiled into a class file.

(4) Compile a program using HelloService. java in the PHP compiler, as shown in List-5. (4) Write a PHP program to call HelloService. java, as shown in List-5. Put sayHello2.php under $ RESIN_HOME/webapps/ROOT/contents. Put sayHello2.php in the $ RESIN_HOME/webapps/ROOT/directory.

List-5 sayHello2.php List-5 sayHello2.php

(5) connect http: // localhost: 8080/sayHello2.php with the ingress connector, resin application server will send $ RESIN_HOME/webapps/ROOT/sayHello2.php to quercuz to compile corresponding java programs, and then parse and parse the lines, the resin application server Returns "Java say hello to Jason", which is displayed on the worker plane. (5) Use a browser to connect to http: // localhost: 8080/sayHello2.php. The resin application server will send $ RESIN_HOME/webapps/ROOT/sayHello2.php to the corresponding java program, then compile and execute the program. Finally, the resin application server Returns "Java say hello to Jason", which is displayed in the browser.

To integrate PHP and Java with Quercus and resin, you only need to install JDK and resin application server (including Quercus ), if you want to collect data, you need to install other data storage servers, such as MySQL Server, the infrastructure is simpler than the integration of SOAP and PHP/Java Bridge. To integrate PHP and Java with Quercus and resin, you only need to install JDK and resin application server (containing Quercus). to connect to the database, you need to install other database servers, such as MySQL Server, environment setting is easier than integrating SOAP with PHP/Java Bridge. However, Quercus and PHP/Zend Engine have compatibility issues. However, quercuus has compatibility issues with PHP/Zend Engine.

Iii. PHP/Java Bridge Iii. PHP/Java Bridge

The interface of Java and script syntax is defined as JSR 223, and JSR is the Specification of Java Specification Requests. The interfaces of Java and script are defined in JSR 223, which is short for Java Specification Requests. JSR 223 defines an interface for creating Java-type entities, call methods, and deliverables from the script statement, it also defines the method for calling script statement from Java, the number of repeated statements, and the method for calculating the return value. JSR 223 specifies the establishment of interfaces for Java class entities, call methods, and result objects from the script language, as well as the methods for calling the script language from Java, conversion parameters, and return value. The following describes how to use the PHP/Java Bridge Suite to enable PHP to use the Java program connector. PHP/Java Bridge is the Java interface of PHP 5 of JSR 223. The following describes how to use the PHP/Java Bridge Suite to allow PHP to use the Java library. PHP/Java Bridge is the Java interface Implementation of PHP 5 in JSR 223.

(1) pre-jobs: Server guard PHP> = version 5.0, JDK> = version 1.4.2, Apache HTTP Server> = version 2.0, and Tomcat (using port 8080 ). (1) pre-job: install PHP> = version 5.0, JDK> = version 1.4.2, Apache HTTP Server> = version 2.0, and Tomcat (use port 8080 ).

(2) Installing PHP/Java Bridge (2) Installing PHP/Java Bridge

  1. First, go to the PHP/Java Bridge website's first website (http://php-java-bridge.sourceforge.net/doc/, please refer to "downloadrunner can be downloaded to sourceforge.net, Please download the php-java-bridge_j2ee.zip file, after resolving the issue, you can get the JavaBridge. war file. First, go to the home page of the PHP/Java Bridge website (http://php-java-bridge.sourceforge.net/doc/ plugin, click "download」can be connected to sourceforge.net, select the download php-java-bridge_j2ee.zip file, after decompression, you can get the JavaBridge. war file. Set unpackWARs in Tomcat server configuration to True, and then export JavaBridge. war to Tomcat's webapps. Set unpackWARs in Tomcat server configuration to True, and then copy JavaBridge. war to the webapps directory of Tomcat. Restart Tomcat to view JavaBridge under the webapps category. Restart Tomcat to view the JavaBridge directory under the webapps directory.
  2. Complete the java sub-projects under the JavaBridge category to the $ PHP_INCLUDE category, and add the $ PHP_INCLUDE category to the include_path of php. ini. Copy the java subdirectory under the JavaBridge directory to the $ PHP_INCLUDE directory, and add the $ PHP_INCLUDE directory to the export de_path of php. ini. For example, if $ PHP_INCLUDE is c:/php5/pear, then export de_path = ".; c:/php5/pear ". For example, if $ PHP_INCLUDE is c:/php5/pear, then export de_path = ".; c:/php5/pear ". The java sub-project contains the original PHP/Java Bridge program using PHP. The java sub-directory contains the original PHP/Java Bridge Code that uses PHP.

(3) Put the List-1 program in the webapps/JavaBridge/WEB-INF/classes/hello/Under the Tomcat project, and upload it. (3) Put the List-1 program in webapps/JavaBridge/WEB-INF/classes/hello/Under the Tomcat directory and compile it.

(4) Compile a program using HelloService. java in the PHP compiler, as shown in List-6. (4) Write a PHP program to call HelloService. java, as shown in List-6. Place sayHello3.php In the DocumentRoot directory of Apache Server. Put sayHello3.php In the DocumentRoot directory of Apache Server.

List-6 sayHello3.php List-6 sayHello3.php

(5) use the zookeeper to connect to http: // localhost/sayHello3.php. In this case, the Apache Server will send sayHello3.php to PHP/Zend Engine zookeeper and zookeeper. (5) Use a browser to connect to http: // localhost/sayHello3.php, the Apache Server will hand over sayHello3.php to PHP/Zend Engine for compilation and execution. When PHP calls the Java program, PHP/Java Bridge (the php program under the java project) converts the call *. the phpjavabridge file format is then sent to the php. java. servlet. phpJavaServlet processing, which is finally returned to PHP through PHP/Java Bridge. When PHP calls the Java library, PHP/Java Bridge (the php program under the java subdirectory) converts the call *. the phpjavabridge file format is then transmitted to the php. java. servlet. phpJavaServlet processing, and finally return the result to PHP through PHP/Java Bridge. After the List-6 program runs successfully, the "Java say hello to Jason" statement is displayed on the worker plane. After the List-6 program is executed, you can see that "Java say hello to Jason" is displayed in the browser screen.

Conclusion Conclusion

Developing Web applications using a single statement is not necessarily the most efficient way. With the development of Web, using a single language to develop Web applications is not necessarily the most efficient way. The introduction in this article may allow Web developers to understand how to use PHP and Java to integrate Web programming skills, we also hope to encourage Web developers to think about and develop better Web application development methods, it is based on the rapid change of electronic sub-generation and the demand for a large number of products. It is expected that the introduction in this article will allow Web developers to learn how to use PHP and Java to develop Web programs in an integrated manner, it is also hoped that Web developers can think about and explore better Web application development methods to respond to the rapid changes in the electronic age and a large amount of information needs.

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.