The birth of the new pet-Java + PHP Integration

Source: Internet
Author: User

I have been researching a new development model over the past few days. So I will post it for you to share. Use open-source LAJP technology.

Purpose:

Verify the two Kingdom languages JAVA/PHP). Different Languages and mechanisms are combined. PHP is responsible for the WEB layer and Java is responsible for the business and data logic layer. This is a golden combination.Java + PHPIntegration=Mixed-race new darling), Give full play to their respective advantages, suitable for developing B/S enterprise programs.

1. Technical Issues

How to communicate with different languages in two different environments? Second, how to handle communication content? Is the development and deployment environment integrated? 1.1 comparison between the two languages Php: Intuitive, fast, simple, easy to learn, highly efficient development of dynamic web pages, strong grassroots culture, is a civilian hero of the language world, focusing on the results. Java: Powerful and complex. It has many high-end functions and is sought after by enterprises such as IMB and Oracle. It is the noble prince of the language world. 1.2 communication problems 1.2.1 Message QueueObserve from the operating system: PHP and Java are different processes running in the system. Communication between them is an inter-process communication technology (IPC ):

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/13344M517-0.jpg "/>

In traditional Unix environments, IPC technologies include pipelines, message queues, shared memory, and semaphores. However, in the same system, IPC communication is superior to TCP-based socket communication in terms of performance and resource usage. In Unix/Linux, PHP basically provides access interfaces for all IPC, because PHP can be seen as a shell with C language as the core, while IPC is an integral part of the system kernel, A group of C function interfaces are provided for external users. Therefore, PHP can smoothly use IPC technology. Java, however, does not provide system-level IPC access in order to pursue platforms (the differences between Windows IPC technology and Unix), which also reflects the cultural characteristics of Java: in pursuit of uniformity, performance can be sacrificed. 1.2.2 SocketMessage Queue Technology can only be applied to Unix/Linux systems, while SOCKET is based on TCP/IP communication mechanisms to adapt to various platforms.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/13344GM7-1.jpg "/>

It can be seen that PHP assumes the responsibility of the HTTP layer, while Java assumes the responsibility of the business layer. they communicate with each other through the System V Message Queue, one of the communication among processes in IPC, java requires support from JNI. Message Queue has the following benefits:

1. keep php and java independent. high transmission speed, greater than socket 3. compared with the socket method, the Java Server only provides services to the local machine (no listening ports), which is relatively secure and easy to manage.

1.3 communication content problemsAfter the communication problem is solved, how can the communication content be solved? Data types defined in PHP and Java are converted when the two languages transmit data to each other? 650) this. width = 650; "alt =" * "width =" 11 "height =" 11 "src =" file: // C:/Users/ADMINI ~ 2/AppData/Local/Temp/msohtmlclip1/01/clip_image001.gif "/> Xml: xml is a data encapsulation technology that can well describe object models, however, xml is large in size and the transmission rate is slow, and parsing at both ends of the communication is also troublesome. 650) this. width = 650; "alt =" * "width =" 11 "height =" 11 "src =" file: // C:/Users/ADMINI ~ 2/AppData/Local/Temp/msohtmlclip1/01/clip_image001.gif "/> serialization: using serialized and deserialized objects to transmit data during transmission is a common and reasonable method, and both languages support this method. 2 Selection of Java and phpCurrently, known integration technologies of PHP and Java on the Web can be divided into three types: SOAPSimple Object Access Protocol, Quercus, and PHP/Java Bridge, these technologies allow PHP and Java to use each other's libraries when developing Web applications.

SOAP SOAP is a protocol developed by IBM, Microsoft, and other companies and recommended by W3C to implement distributed object technology. SOAP provides a set of mechanisms for packaging program calls, parameter transfer, and information return using XML. With the help of the characteristics of XML plain text, you can use HTTP, HTTPS, SMTP, and other communication channels to penetrate the Enterprise Firewall. 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.
Quercus Quercus is an open-source PHP 5 engine and has full implementation of pure Java. Quercu runs on the Resin application server and utilizes the Resin features such as load balancing and proxy cache.
PHP/Java Bridge Open-source products: Php-java-bridge and LAJP

2.1 selection criteriaÜ free and open-source ü easy to use ü efficient and stable 2.2 LAJP 2.2.1 featuresØ Complementary advantages:PHP is a very popular WEB programming scripting language. It features easy to learn, easy to use, and high development and deployment efficiency. It is very suitable for WEB programming. JAVA is suitable for compiling programs with complex business functions and data, the combination of the two can give full play to their respective advantages. Ø Efficient and stable: Apache + PHP combination can bring excellent WEB service stability, while JAVA can supplement high-end features such as connection pool, thing management, distributed, object model, etc. Ø Innovative communication mechanism: The communication methods between PHP and Java adopt the system message queue and Socket mechanisms, taking into account the communication efficiency and platform compatibility. Ø Automatic data type conversion mechanism: PHP Data and Java data can be accurately and automatically matched and converted without the need for programmers to write parsing code. Ø Easy to use: LAJP is easy to install and configure. PHP and JAVA programming are in line with their respective programming habits. Ø Lightweight: The LAJP architecture is very lightweight. In addition to the most basic PHP and Java environments, there is no need for any extended, third-party components or containers. 2.2.2 data type conversionPHP and Java have their own data types defined internally. When PHP data is transmitted to Java or Java data to PHP, LAJP automatically and accurately converts them internally, programmers do not need to perform any decoding work.

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/13344G1U-2.jpg "/>

2.2.3 lalkaline running environment Message Queue ModeThe environment must meet the running requirements of the System V Message Queue:
  • SystemCurrently, Common Unix/Linux systems can support php (Apache) and java operations. Most of them Support System V message queues by default.
  • PhpPhp needs to communicate with java processes through message queues. According to php instructions, php supports System V message queues after version 4.3.0.
  • ApacheNo special requirements. It is enough to meet php requirements.
  • JavaThe java version is later than 1.5.
  • Message Queue mode is recommended in Unix/Linux environments.
Socket Mode
  • SystemNo restrictions. It is difficult to find a system that does not support TCP/IP.
  • PhpAccording to php instructions, php version> = 4.1.0 supports socket
  • ApacheNo special requirements. It is enough to meet php requirements.
  • JavaThe java version is later than 1.5.
  • Windows only supports socket mode.
Both modes can be used during development. For example Windows Environment, and the program is deployed in Linux System, LAJP The mode configuration is not related to the encoding. 2.2.4 deployment 2.2.4.1 distributed architectureIn important and critical business scenarios, the user interaction layer and business layer are deployed separately. LAJP can use this architecture as follows: 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/13344M091-3.jpg "/> Java in WEB servers is a very thin layer, only used to connect to the following EJB service. 2.2.4.2 ClusterWith the increase in user traffic, WEB services often become a bottleneck in the system. The following is the architecture reference of LAJP in the Cluster:

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/13344K361-4.jpg "/>

2.2.4.3 web ClusterBy using the socket communication mode LAJP, you can build a simple distributed WEB Cluster architecture:

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/13344L2O-5.jpg "/>

2.2.4.4 complex architecture applicationsLAJP is flexible in use. The design and selection of the architecture lies in our own ideas. The following Architecture references use clusters at the WEB layer and EJB layer:

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/13344M449-6.jpg "/>

Memcache is a distributed memory object caching technology. In PHP, Session data can be conveniently stored in it to synchronize data from nodes in the WEB Cluster, it can also be reflected in the "professional" of PHP in the WEB field compared with Java ".

This article from the "blow cowhide pull submarine train Japanese aircraft" blog, please be sure to keep this source http://cabmjckx.blog.51cto.com/665504/596334

Related Article

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.