驗證兩種各自領域稱王的語言(JAVA /PHP),不同語言、不同機制的組合在一起,PHP負責WEB層,Java負責業務與資料邏輯層,真是一對黃金組合(Java PHP整合=混血新寵兒),發揮各自優勢,適合開發B/S企業程式。
1、技術問題
##兩種不同環境,不同機制的語言結合,首先要解決的是如何通訊?其次是通訊內容如何處理?最後是兩者開發,部署環境整合?1.1兩種語言比較
Php:直觀,快速,簡單,易學,開發動態網頁效率高,草根文化氣息濃重,是語言世界的平民英雄,注重結果。
Java:強大而複雜,有眾多高階功能,又有IMB、Oracle等企業大顎的追捧,是語言世界的貴族王子。
1.2通訊問題
1.2.1訊息佇列
#從作業系統層面觀察: PHP和Java是系統中執行的不同進程,他們之間溝通屬於進程間通訊技術(IPC):
在傳統的Unix環境中,IPC技術有:管道、訊息佇列、共享記憶體、訊號量等,但在同一個系統中,IPC通訊比基於TCP的socket通訊在效能、資源佔用方面有相當大的優勢。
在Unix/Linux中,PHP基本上提供了所有IPC的存取接口,因為PHP可以看作是以C語言為核心的一個殼,而IPC是系統核心的組成部分,對外提供了一組C函數接口,因此PHP可以非常順暢的運用IPC技術。而Java為了追求誇平台性(Windows的IPC技術和Unix的不同),沒有提供系統級的IPC訪問,這也體現了Java的文化特色:為追求統一可犧牲效能。
1.2.2 Socket
訊息佇列技術只能適用於Unix/Linux系統,而SOCKET則是基於TCP/IP的通訊機制,進而適應各種平台。
####################### #從上圖看出,PHP承擔HTTP層的職責,而Java承擔業務層的職責,他們透過System V Message Queue(訊息佇列,進程間通訊IPC中的一種)相互溝通,Java需要JNI的支持。 ######使用訊息佇列有以下好處:###
1. 讓php和java保持獨立性 2. 有極高的傳輸速度,大於socket 3. 相對於socket方式,Java服務端只提供服務給本機(沒有對外偵聽埠),相對安全,易於管理。 |
1.3# 通訊內容問題
##通訊問題解決了,通訊內容該如何解決?
PHP和Java各自語言內部定義的資料類型,當兩種語言互相傳輸資料時,資料類型怎麼會轉換呢?
(1)Xml: xml確是一種誇張平台、能很好描述物件模型的資料封裝技術,但xml體積大傳輸速率慢,通訊兩端解析也比較麻煩。
(2)###### 序列化: 在傳輸過程中使用序列化和反序列化物件傳輸資料是一種公認且比較合理的方式,且兩種語言都支援。 ###### ###
2、#Java與php 結合選型
#目前已知的PHP與Java在Web間整合技術可分成SOAP(Simple Object Access Protocol)、Quercus、PHP/Java Bridge三種,這些技術可以讓PHP與Java在開發Web應用程式時互相使用彼此的程式庫。
#SOAP |
SOAP是IBM、 Microsoft等公司開發、W3C推薦,用來實現分散式物件技術的協定。 SOAP提供了一套以XML來包裝程式呼叫、參數傳遞與資訊回傳的機制,借助XML純文字的特性,可透過HTTP、HTTPS、SMTP等通訊管道穿越企業的防火牆。比起CORBA、Java RMI及DCOM這些以專屬binary格式傳送資料的分散式物件技術協議,SOAP具有與程式語言、平台和硬體無關的特性。 |
Quercus # |
Quercus是一個開源 PHP 5 引擎,它已經擁有了純 Java 的完整實作。 Quercus 在 Resin 應用伺服器之上運行,利用了負載平衡、代理快取等 Resin 功能。 |
PHP/Java Bridge |
#開源產品有:Php-java-bridge 與LAJP |
2.1# 選擇條件
ü 免費、開源
ü 簡單易用
##ü 高效穩定
2.2 LAJP
####################################################################################2.2.1 Features
Ø Complementary advantages: PHP is a very popular WEB programming script language. It is easy to learn, easy to use, and has high development and deployment efficiency. It is suitable for writing programs with complex business functions and data. The combination of the two can give full play to their respective advantages.
ØEfficient and Stable: The Apache PHP combination can bring excellent WEB service stability, and JAVA can supplement such as connection pooling, transaction management, distribution, and objects models and other high-end features.
ØInnovative communication mechanism: The communication between PHP and Java uses two mechanisms: system message queue and Socket, taking into account communication efficiency and platform compatibility.
ØData type automatic conversion mechanism:
PHP data and Java data can be automatically matched and converted accurately, without the need for programmers to write parsing code. Ø Easy to use: LAJP is easy to install and configure, and PHP and JAVA programming conform to their respective programming habits. Ø Lightweight: The LAJP architecture is very lightweight. In addition to the most basic PHP and Java environments, it does not require any extended or third-party components. container. 2.2.2 Data type conversion PHP and Java each have their own data types defined internally in the language. When PHP data is transferred to Java, Or when Java data is transmitted to PHP, LAJP automatically and accurately converts them internally, and programmers do not need to perform any decoding work. ##2.2.3 LALP Running environment Message queue mode The environment needs to meet the operation of System V message queue: System Currently common Unix/Linux systems can be used Meet the operation of php (Apache) and java, most of which support System by default
V message queue. php PHP needs to communicate with the java process through the message queue. According to PHP instructions, PHP is in 4.3. System V message queue is supported after version 0. apache No special requirements, just meet the PHP requirements. java The java version is after 1.5. In a Unix/Linux environment, it is recommended to use the message queue mode. ##socket mode ##System There are no restrictions and it is difficult to find a system that does not support TCP/IP. According to the instructions of php, php version >=4.1.0 supports socket apache No special requirements, just meet the PHP requirements. java The java version is after 1.5. Windows system can only use socket mode These two modes can be used at the same time during the development process. For example, generally developers use the Windows environment, and the program is deployed in the Linux system. The configuration of LAJP mode has nothing to do with coding. #2.2.4 Deployment 2.2.4.1 Distributed architecture Java in the WEB server is a very "thin" layer, only used to connect to the subsequent EJB services. 2.2.4.2 By using LAJP in socket communication mode , you can build a simple distributed WEB cluster architecture: ##2.2.4.4 Complex Architecture Application memcache is a distributed memory object caching technology. In PHP, it is very convenient to store Session data in it to synchronize each node in the WEB cluster. The data can also reflect PHP's "professionalism" compared to Java in the WEB field. This article introduces the relationship between Java and PHP. For more related content, please pay attention to the php Chinese website. Related recommendations: ##2.2.4.3 web cluster
以上是Java與PHP之間的關聯的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本文討論了PHP中的crypt()和password_hash()的差異,以進行密碼哈希,重點介紹其實施,安全性和對現代Web應用程序的適用性。

文章討論了通過輸入驗證,輸出編碼以及使用OWASP ESAPI和HTML淨化器之類的工具來防止PHP中的跨站點腳本(XSS)。

自動加載PHP會在需要時自動加載類文件,從而通過減少內存使用和增強代碼組織來提高性能。最佳實踐包括使用PSR-4和有效組織代碼。

本文討論了在PHP中管理文件上傳大小的管理,重點是2MB的默認限制以及如何通過修改PHP.INI設置來增加它。

本文討論了PHP 7.1中引入的PHP中的無效類型,允許變量或參數為指定類型或NULL。它突出顯示了諸如提高可讀性,類型安全性和明確意圖的好處,並解釋瞭如何聲明

本文討論了unset()和unlink()功能在編程中的差異,重點關注其目的和用例。 unset()從內存中刪除變量,而unlink()從文件系統中刪除文件。兩者都對效率至關重要


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。