开发者

Php/Java Integration

开发者 https://www.devze.com 2023-01-08 08:36 出处:网络
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

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

$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.

Thanks in advance


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


Have a look at:

PHP-Java Bridge

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.


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 machine you 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.


Check out this article: 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...


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.


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)

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

0

精彩评论

暂无评论...
验证码 换一张
取 消