How to use Java with PHP 5

I looked through quite a few tutorials on using Java from PHP, but they seem to conflict with eachother. Many of them talk about changing php.ini to use a DLL file, but it seems that PHP 5 has built-in features. But does this require Tomcat? Do I have to get rid of Apache to run this? http://php-java-bridge.sourceforge.net/pjb/installation.php says that it places the .war file in the Tomcat autocploy directory, but I don’t see any directory called "autodeploy". Someone explain step by step how to make Java stuff work on a Windows machine (I use Windows 7) with PHP 5 and Apache?

+7
source share
3 answers

You will probably find a ton of useless and outdated information on how to use Java classes from your PHP web application, which doesn't help at all. About a year ago, I had a similar problem, and I found out that the only way that is mature enough to use in production is PHP / Java Bridge - the one you found in Sourceforge. It works better than you might expect and does not require knowledge of Java (however, if you know Java, you should consider writing a web service for this purpose and use it on the PHP side).

The documentation on Bridge is not very obvious, however, remember that you should adhere to it and not read other resources describing different methods - do not mix things, that is, you do not need to install any PHP extensions or smth - they are all connected with others ( usually outdated and unsupported) ways to call Java from PHP.

PHP / Java Bridge is a network protocol, so the only thing you need on your PHP side is to enable "allow_url_include" in php.ini

On the Java side, you need to get PHP / Java Bridge to bind to a free port and listen for connections. Then your PHP application will be able to execute the "require_once" proxy of the Bridge file, which will be available on this port. That he and you can create and call Java classes transparently from your PHP script using this proxy Bridge object (it will serialize and pass calls and results backstage).

There are two options: how to get a bridge and bind it to a local port.

1) complicated: configure Tomcat, create a war file with the bridge itself and the library that you want to use. This method is described here:

http://php-java-bridge.sourceforge.net/pjb/webapp.php

To deploy a war in your Tomcat installation, just put the war in the Tomcat webapp folder and restart it.

2) easier: pack the jar instead of war and run it (it will use the built-in web server, so you do not have to install Tomcat and deploy anything). To do this, go to this page:

http://php-java-bridge.sourceforge.net/pjb/desktop-apps.php

Both methods will work for you (do not look at the word "desktop" in the second option, so it works perfectly with your PHP server as well).

See the examples on how to use it in the "Examples" section (obvously). You can also contact my little PHP client who talks about the built-in Neo4J database in Java using PHP / Java Bridge. However, this example may be more complex and was intended to be deployed in Tomcat, anyway you may have an idea of ​​how to instantiate and use classes from it:

https://github.com/coffeesnake/neo4j-php-wrapper

+13
source

You can simply call a simple Java application from PHP by opening the process and passing it through stdin / stdout. Alternatively, if you integrate Sphinx into a webapp, you can integrate it through HTTP calls.

+1
source

Quercus :

Quercus is an open source Coucho Quick technology, 100% Java implementation in PHP. Quercus is a feature of the resin processing application server based on Caucho Technology and is built into Resin - there is no additional download / installation. Developers using Resin can run PHP projects without installing the standard PHP interpreter ( http://www.php.net ), since Quercus takes on the role of the PHP engine.

+1
source

All Articles