PHP 7.1.0 Released

Java Functions

Table of Contents

add a note add a note

User Contributed Notes 16 notes

10 years ago
For those who want to run php with a recent tomcat version, you'll need the following patch:
rabisultan at gmail dot com
10 years ago
If you get this error

Fatal error: Unable to create Java Virtual Machine in

it can be fixed by modifying your php.ini file, you will need to add in the path to the JRE's lib folder.

My php.ini file (php4/Apache2):
java.class.path= "e:\minerva\php\extensions\php_java.jar; c:\j2sdk1.4.2_08\jre\lib; C:\j2sdk1.4.2_08"
java.home = "c:\j2sdk1.4.2_08\bin; c:\j2sdk1.4.2_08\jre\lib"
java.library = "c:\j2sdk1.4.2_08\jre\bin\server\jvm.dll"
java.library.path= "e:\minerva\PHP\extensions; c:\j2sdk1.4.2_08\jre\lib"
m mokhtar at gmail dot com
11 years ago
Getting PHP JavaBridge to work with PHP5 on windows server:
1- Install Java J2EE 1.5 + JDK 1.4 (which includes application server/deploy tool/etc...)
2- download and, which will include
extra dll(s)
    - unpack pecl pkg to your extensions folder, in PHP5 its ext.
    - unpack java-Bridge to root php folder, in my case its simply C:\PHP
    Note: the java-Bridge inculdes new versions of certain files like php_java.dll
    so, it would be wise to rename your old files that came with PECL pkg for example
    file_old, to rollback at anytime.

In order to deploy/test Java-Bridge .war onto your java application server follow these steps

Note: move JavaBridge.jar to your extensions folder. and in test.php file that came
with Java-Brdige package change line java_require("test/arrayToString.jar");
to java_require("tests.php4/arrayToString.jar");

Add the following to your php.ini file and restart server:-
java.classpath = "location of JavaBridge.jar file...i.e. to your PHP extensions folder\
JavaBridge.jar,also any other extra java files that you'll be instanciating using your php script"
java.java_home = "location of jdk\bin"
java.libpath = "location of php_java.dll file...i.e. also to your PHP extensions folder"

happy integration

stanley dot turnteen at gmail dot com
11 years ago
The php-java-bridge from sourceforge works great - it's stable and fast. I'm using it with the Lucene full text indexing package (
beoran at gmail dot com
11 years ago
The php-java-bridge mentioned below is indeed the way to go. It also works fine on a php 4.3.2 Linux web server. I think I can reccomend it.
11 years ago
<quote> JVM runs fine the first time, then broke....  </quote>

The php4 java extension is simply broken, don't use it.  I am
using the "PHP Java Bridge" for PHP5 with great success on WinNT:
jost2345 at yahoo dot de
12 years ago
The PHP/Java bridge that has been posted some time ago is now available on  It contains several bugfixes and is meant to be used as a replacement for the expermental PHP4 java bridge.

So please don't send me private e-mails anymore to obtain the sourcecode for the bridge.

PHP/5 users may want to wait for the official PHP/Java bridge, which I expect to appear in a few years when java contains the appropriate hooks.
okapi at yahoo dot com
12 years ago
As mentioned prior, Zend is working to be the first of an official servlet / scripting integration. I've been testing their reference implementation that's available on the JSR 223 site and it's working pretty good. Some minor issues around the edges, but been working with one of their developers to fix it. So far, pretty good.
a9702466 at gmx dot net
12 years ago
The Java Servlet SAPI works fine in a non-threading
environment. If you want to use threads (normal case) you
have to do several things to get it work:

- get the patched files from

- replace the sapi/servlet/ and
  sapi/servlet/servlet.c file by the patched files

- build the php like this
  ./configure --with-tsrm-pthreads \
    --with-servlet=/opt/resin --with-java=/opt/java \

The primary problem is, that the request and response
objects are stored as global instance-variables of the servlet
which will be overwritten by other threads invoking the
servlet (remember: just on servlet-object for all threads!) and
all crashes. I changed the servlet to pass the request and
response objects to the java- and native-methods (where
required) to prevent the problem.

Once you have solved this problem it works fine and needs
unlike the java-extension just one jvm.
norman at junkonline dot com
12 years ago
This works fine on MacOS X (Panther). The one trick is, you need to symlink "" in your php extensions directory to "libphp_java.jnilib".

Here's the relevant section from my php.ini file for anyone who needs it:

java.class.path = "/usr/local/lib/java/php_java.jar"
java.home = "/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home"
java.library.path = "/usr/local/lib/php/extensions/no-debug-non-zts-20020429"

You may have decided to put php_java.jar somewhere other than where I did.

For some reason, setting java.library in the ini file causes this to fail, so I left it out and things worked flawlessly without it. YMMV.
georgedaswani at hotmail dot com
12 years ago
I was able to compile java support in no problem and got it working sun jdk 1.4.2_03 (linux)

make sure JAVA_HOME is set

make sure LD_LIBRARY_PATH has


on php.ini

java.home = "/opt/j2sdk1.4.2_03"
java.class.path = "/opt/php/lib/php/php_java.jar:/opt/php/java-packages"
java.library.path = "/opt/php/lib/php/extensions/no-debug-zts-20020429"
extension_dir= "/opt/php/lib/php/extensions/no-debug-zts-20020429"
extension =

It's import to note that APACHE 2 needs to be compiled using "PREFORK" instead of a thread based else the java stuff will work for a minute, then stop working with the following error

"PHP Fatal error:  Unable to create Java Virtual Machine"

Seems that the extension is not thread safe.
golob a with tail gimb little spot org
13 years ago
This module allows PHP to interact with some interesting pieces of software - for one, it allows PHP to convert XML FO files into PDF/PS/... with the use of Apache FOP processor.

Here's an example:
$basedir = new Java("", ".");
$outdir = new Java("", "out");

$fofile = new Java("", $basedir, "xml/fo/");
$pdffile = new Java("", $outdir, "ResultFO2PDF.pdf");

echo "Input: ".$fofile->toString()."\n";
echo "Output: ".$pdffile->toString()."\n";

$driver = new Java("org.apache.fop.apps.Driver");
$logger = new Java("org.apache.avalon.framework.logger.ConsoleLogger");
$out = new Java("", $pdffile);
$in = new Java("", $fofile);
$driver->setInputSource(new Java("org.xml.sax.InputSource", $in));
Magnus_Naeslund at nowhere dot to dot be dot found
14 years ago
An _very_ important thing here is to remember that the apache must be linked with pthreads (do "LDFLAGS=-lpthread ./configure <options>", or like me, add it the the .spec file).
You can check if your apache is pthreaded with "ldd $(which httpd)" if you like.
I experianced a lot of hangs/errors due to this problem, it's a shame that it's not in the docs / README (i didn't find it).

Vikas Kumar
9 years ago
wamp5_1.7.2.exe+jdk1.5.0_10 integration error
java.home="C:\Program Files\Java\jdk1.5.0_10; C:\Program Files\Java\jdk1.5.0_10\lib"
java.class.path="C:\wamp\php\ext\JavaBridge.jar; C:\Program Files\Java\jdk1.5.0_10\lib"
java.library.path="C:\wamp\php\ext; C:\Program Files\Java\jdk1.5.0_10\lib"
java.library="C:\Program Files\Java\jdk1.5.0_10\jre\bin\server\jvm.dll"
meaton53 at hotmail dot com
10 years ago
I just wanted to post this for people that were having the same troubles that I was having.  I am running OES SuSe Linux 9-1.  I started this adventure because I needed to connect to a progress database via PHP.  And I couldn't use ODBC drivers because the progress ODBC drivers were simply to old for unixODBC and iODBC (progress 9.1c).  So I had to use JDBC with this wonderful PHP extension along with the PHP-Java Bridge found at:
So Just for some notes, in the PHP.INI file I had to have:

And be careful because lots of sites tell you that the two varibles above are java.class.path, and java.library.path.

And also to be able to connect to a progress database from java in Linux you have to set your LD_ASSUME_KERNEL varible to 2.4.0 to do this simply add to you profile.local file:
export LD_ASSUME_KERNEL=2.4.0. 
If you want to know why please email me and I will tell you.
alexg at syspro dot co dot za
14 years ago
According to an Article posted at:

there might be some problems with getting php and jdk-1.4 to work toghether.. I`ve tried (php-4.2.2 and jdk-4.1) with no success....
To Top