PHP/Java 集成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3319161/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 01:17:42  来源:igfitidea点击:

Php/Java Integration

javaphp

提问by Novice

Have you experience of integration of php and Java? I've written a class in Java "Hello". Now I want to call its method from php when I create an instance of this class from php with

你有php和Java集成的经验吗?我用Java“Hello”编写了一个类。现在,当我从 php 创建此类的实例时,我想从 php 调用它的方法

$obj = new Java(Hello);

Then it gives me fatal error. I've tried many times to setup php ini variables etc but I couldn't find anything. Please advice me how can I set it up.

然后它给了我致命的错误。我已经尝试了很多次来设置 php ini 变量等,但我找不到任何东西。请建议我如何设置。

Thanks in advance

提前致谢



Reference: http://php.net/manual/en/book.java.php

参考:http: //php.net/manual/en/book.java.php

回答by Sarfraz

Have a look at:

看一下:

PHP-Java Bridge

PHP-Java 桥接

The PHP/Java Bridge is an implementation of a streaming, XML-based network protocol, which can be used to connect a native script engine, for example PHP, Scheme or Python, with a Java virtual machine. It is up to 50 times faster than local RPC via SOAP, requires less resources on the web-server side. It is faster and more reliable than direct communication via the Java Native Interface, and it requires no additional components to invoke Java procedures from PHP or PHP procedures from Java.

PHP/Java Bridge 是一种基于 XML 的流式网络协议的实现,可用于将本机脚本引擎(例如 PHP、Scheme 或 Python)与 Java 虚拟机连接起来。它比通过 SOAP 的本地 RPC 快 50 倍,在 Web 服务器端需要更少的资源。它比通过 Java 本机接口的直接通信更快、更可靠,并且不需要额外的组件来从 PHP 调用 Java 过程或从 Java 调用 PHP 过程。

回答by Gordon

Could it be you are just missing the quotes around the Java Class? Also make sure you actually do have a Java VM on the machineyou are trying to run the code on and make sure you have properly set up the config options. Also, the Java extension is a PECL extension and has to be installed.It is not part of the native distribution. Furthermore, the extension is considered unmaintained and dead, so you might want to have a look at the JavaBridge suggested elsewhere. Zend Server also brings a JavaBridge.

难道您只是缺少 Java 类周围的引号?还要确保在尝试运行代码的机器上确实有 Java VM,并确保正确设置了配置选项。此外,Java 扩展是 PECL 扩展,必须安装。它不是本地发行版的一部分。此外,该扩展被视为未维护且已失效,因此您可能需要查看其他地方建议JavaBridgeZend Server 还带来了 JavaBridge。

回答by Sailab Rahi

There are many ways few are:

有很多方法很少是:

  • PHP Java Bridge
  • Java Integration in PHP
  • Using web services to pass data in between like SOAP
  • Using simple HTTP data passage between Java and PHP see (facejar uses the same technique)

  • Client site script (AJAX)

  • PHP Java 桥
  • PHP 中的 Java 集成
  • 使用 Web 服务像 SOAP 一样在它们之间传递数据
  • 在 Java 和 PHP 之间使用简单的 HTTP 数据通道参见(facejar 使用相同的技术

  • 客户端站点脚本 (AJAX)

If you are after security, use option 1 otherwise I prefer using option 4 which is a bit faster when it comes to performance.

如果您追求安全,请使用选项 1,否则我更喜欢使用选项 4,它在性能方面要快一些。

回答by ircmaxell

Check out this article: http://www.devshed.com/c/a/PHP/Using-PHP-with-Java/

看看这篇文章:http: //www.devshed.com/c/a/PHP/Using-PHP-with-Java/

They say it's possible (and how to do it). I've never done it, so I can't vouch for it...

他们说这是可能的(以及如何做到)。我从来没有做过,所以我不能保证......

回答by DBQ

In my experience the best way to interact between Java and PHP is through a WebService layer. NuSoap for PHP is very good, and you can consume the webservice in Java to create a stub that will build the request/response object.

根据我的经验,Java 和 PHP 之间交互的最佳方式是通过 WebService 层。NuSoap for PHP 非常好,您可以使用 Java 中的 webservice 来创建一个将构建请求/响应对象的存根。