How do I add a Java backend to an existing PHP site without adding a tomcat server for Java Bridge?

拟墨画扇 提交于 2019-12-07 05:28:25

问题


Currently we're using PHP for our websites. Now we're thinking about writing the backend in Java, because of the type safety of the language, and the availability of all kind of tools for Java. I've been reading about Java Bridge and now I'm wondering how to set this up.

We're using PHP already through Apache. I read that to use Java Bridge I need to install Tomcat as well. That means I have two servers (Apache and Tomcat), and I need to add security to the backend, because it is open to the whole wide world suddenly... Am I missing something? Is there another way to make the PHP-Java connection without an additional server? How is this usually done?

Any directions or links on how to to do this or any best practices on how to set it up are greatly appreciated. I didn't find the official Java Bridge site very clear. Thanks!


回答1:


I am currently testing the use of the Zend Java bridge. Two weeks ago, I did test the PHP/Java bridge open source solution. This one does require that you put your java classes into a war deployed in a web server (I did use Tomcat 6). The Zend solution does not require a web server. If you put your business logic in plain java classes, you simply wrap your classes in one (or several) jars. You then start the Zend java bridge daemon into a JVM, passing to the -classpath the Zend Java bridge jar aswell as your own jar's

Ex from a dos windows:

C:\Development\ToolsPHP\ZendServer\bin>java -classpath javamw.jar;mybusinesslogic.jar -Dzend.javamw.port=10002 com.zend.javamw.JavaServer.

Here, I had to specify a port since the 10001 port, which is the default for the bridge, was already in use (use netstat -a to detect port conflicts). Note that the Zend solution only works if your php script is executed on the Apache server managed by the Zend server (community or commercial edition) and that the Zend Java bridge service is running, with its port set to 10002 with the Zend server admin console.

To implement my business logic, I plan using simple Java pojo's, Spring, JPA and Hibernate.




回答2:


You don't need tomcat. As per instructions you can start Java as

java -Djava.ext.dirs=lib -jar JavaBridge.jar HTTP_LOCAL:8080 2 logfile &

lib contains the Java libraries you want to use.

Peter




回答3:


Ok, I am not expert on this. Basically, not even one-eyed. But afaik your options are pretty much the following

For the JavaBridge you have to have a TomCat server.
There is also a JavaBridge in Zend Server CE.
And there is Quercus

Well, and the old PHP4 extension




回答4:


You can look at Gearman. its not exactly, what you are looking for, but it allows Clients and Workers in different languages. As a nice side effect it allows parallel processing with background jobs ;)



来源:https://stackoverflow.com/questions/4292512/how-do-i-add-a-java-backend-to-an-existing-php-site-without-adding-a-tomcat-serv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!