You can check that the extension has been loaded with a little phpinfo script. The output should contain a java extension section. A first step to see if the extension has been loaded with correct settings.
Thomas
You can check that the extension has been loaded with a little phpinfo script. The output should contain a java extension section. A first step to see if the extension has been loaded with correct settings.
Thomas
Thomas.
I successfully ran the phpinfo script, and indeed do have a java section!!
It looks like you were exactly correct on the version problem.
Thanks again. I will do a complete test tomorrow and let you know the results.
Paul
Thomas,
After yesterday's success, I thought I was into clear sailing. But, I am unable to execute the java part of a simple program.
java.class.path ="c:\javaclasses ; c:\php5\php_jar" with my helloapp.java and helloapp.class located in the c:\javaclasses.
My php file : helloapp.php is located in c:\program Files\apache\apache2\htdocs
The helloapp class program contains the main and inside of that system.out.print statement of "helloworld". My php file is a one liner: exec("java Helloapp"}; (This statement was enclosed in <? php and ?> .
php runs fine, but it is the embedded java that doesn't work. Am I on the right track?
Sorry, I don't understand how to run example 1. I thought one has to first compile a java source program creating a .class file from a .java source. Then one would run the php program which contains a reference to the .class file. (By the way, I tried the Example 1 called in the Apache htdocs file. System locked up!)
Paul
How does the java section look like in the phpinfo() output ?
Here is the info in the java section of phpinfo:
java
Directive Local Value Master Value
java.class.path
(local value) c:\php5\php_java.jar;c:\javaclasses
(master value) c:\php5\php_java.jar;c:\javaclasses
java.home
(local value)c:\Program Files\java\jdk1.5.0_06\bin
(master value)c:\Program Files\java\jdk1.5.0_06\bin
java.library
(local value)c:\Program
Files\java\jdk1.5.0_06\jre\lib\bin\server\jvm.dll
(master value)c:\Program
Files\java\jdk1.5.0_06\jre\lib\bin\server\jvm.dll
java.library.path
(local value) c:\php5\ext\
(master value)c:\php5\ext\
Hope you could read this OK
Paul
Ok,
I think the java_home path is wrong.
Copy the php_java.jar to the ext folder and then try the following settings:
java.class.path="C:\php5\ext\php_java.jar;C:\javaclasses;C:\Program Files\java\jdk1.5.0_06\jre\lib;C:\Program Files\java\jdk1.5.0_06"
java.home="C:\Program Files\java\jdk1.5.0_06"
java.library="C:\Program Files\java\jdk1.5.0_06\jre\bin\server\jvm.dll"
java.library.path="C:\php5\ext;C:\Program Files\jdk1.5.0_06\jre\lib"
I'm not sure if those settings are completely correct. Check the paths. I checked my jdk 1.5.0_06 installation and the jvm.dll is in ...\jre\bin\server and not in ..\jre\lib\bin\server.
An alternative is the PHP/Java bridge. I compiled and successfully used it on a linux box but there's a binary package available that contains the windows files, too. Those file are packaged in the .war file that comes with the zip package.
Thomas
Thomas,
I implemented all of your file changes, and still get no response from java.
I looked at the Apache error log for the last time I tried to connect. It read something like:
"java.lang.noClassDefFoundError: javaprog."
javaprog is the .class file that contains the compiled java code. Perhaps this is a clue.
Thanks again for your patience and help.
Paul
That means that java couldn't find your class.
What about this example (taken from the manual) ?
<?php
// get instance of Java class java.lang.System in PHP
$system = new Java('java.lang.System');
// demonstrate property access
echo 'Java version=' . $system->getProperty('java.version') . '<br />';
echo 'Java vendor=' . $system->getProperty('java.vendor') . '<br />';
echo 'OS=' . $system->getProperty('os.name') . ' ' .
$system->getProperty('os.version') . ' on ' .
$system->getProperty('os.arch') . ' <br />';
// java.util.Date example
$formatter = new Java('java.text.SimpleDateFormat',
"EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz");
echo $formatter->format(new Java('java.util.Date'));
?>
Execute this script and check if it prints anything. Check the error log if it contains any error.
Please post the source file of your java example as an attachment.
Thomas,
I placed your test php file(Thomas.php) in c:\Program Files\Apache Group\Apache2\htdocs. (I think that this is where it should be placed. Correct??)
When I went to the browser and went to http://localhost/thomas.php I get a pop up message box saying: "Apache HTTP server has encountered a problem." I looked at the error report and it was as follows: "szAppName:Apache.exe szAppVer 2.0.52.0"
The Apache error log didn't show anything unusual. (something about aquiring the start mutex).
I will send another message with my test program which you asked for.
To be sure I understand, I put all .php files that I wish to post in the htdocs file. I put all .class files associated with these .php files in c:\javaclasses which is on the java.class.path.
Is this correct?
(These .class files were created by separately compiling .java files.)
In the case of Thomas.php there is no associated .java file so there is no compiling to be done. Correct?
Thanks again for sticking with this.
Paul
This is a second message, please read the first one that I wrote a few minutes ago.
Here is the test code that I have been using.
<?php
echo "Hello World!" ;
$output = array();
$return_var = 0;
exec("java javaprog", $output, $return_var);
$output_str = join($output, "\n");
echo "<pre>The output was:\n$output_str\n\n";
echo "The return value was $return_var</pre>";
?>
// Here is javaprog.java
public class javaprog
{
public static void main(String[] args)
{
System.out.println("Printed by Java program");
System.exit(8) ;
}
}
The error message means that apache crashed with the test script I posted. That's a bigger problem meaning that for some reason the java extension is instable.
Your script executes java externally with the exec function. You don't need the java extension for that. The java extension enables PHP to access java classes in a PHP like style.
Please give me more info about your setup (apache version, php version, MySQL version, ....).
I'll try to reproduce the problem.
Thomas
I hope this helps:
System:
MS Windows XP Media Center Edition Version 2002 Service Pack 2
IE 6.0
AMD Athlon Prcoessor 3700+
Java version jdk1.5.0_06
Apache Version 2.0.52
PHP Version 5.0.2
MySQL Server 5.0
PECL (java pecl for PHP) 5.0.2
I am still quite confused.
Question 1 My test program required that I off line compile the .java file. Then The system should be able to locate the corresponding .class file. Is this correct? You are saying that doing things this way does not require adding the java extension.? If this is true is it sufficient to store the .class file in java.class.path ? If the java extension were working, php would automatically compile the .java file??
Question 2 Your test program calls up some java classes. These are part of the java.lang,system package which are usually loaded automatically in java. Therefore the java extension seems to be able to find these classes. Correct? I there were any external new classes these would have had to be converted to .class files ?
Comment: Due to my unfamiliarity, I have a feeling that part of the problem here is my misunderstanding of what is going on. (So called "cockpit problems")
Paul
Paul
Hi,
I was able to reproduce your problem. Apache crashed whenever I tried to do some java stuff.
But I was able to solve the problem on my machine by using the PHP/Java bridge.
What you need to do:
1) upgrade to the latest php 5.0 version (php 5.0.4). You can download it by clicking on the "our releases page" link on the left side of the download page.
Download the php 5.0.4 windows binary and the corresponding pecl package (the "collection of pecl modules" link in the php 5.0.4 download section). You need php 5.0.4 because the bridge is incompatible with 5.0.2
2) download the php/java bridge and extract the archive. There will be a .war file besides some other files. Rename the file to .zip and open it with winzip. Extract JavaBridge.jar and copy it to the <PHP>\ext directory. Extract php-5.0-java-x86-windows.dll, rename it to php_java.dll and also copy the file to <PHP>\ext.
3) Edit php.ini and replace the java settings lines with:
java.java = "C:\Java\jdk1.5.0_06\bin\javaw.exe"
java.java_home = "C:\Java\jdk1.5.0_06"
java.log_level = 3
java.libpath = "C:\WAMPP\php5\ext"
java.class.path = "C:\WAMPP\php5\ext\JavaBridge.jar"
(modifiy the paths so that they match your java/php installation)
Then execute the test script I posted above. It worked multiple times without any crashes on my system.
One hint: Normally you need to add your own custom jar files to the class path. Instead of modifying php.ini and adding the jar files to the classpath you can do the following:
$javaLibs ="file:c:/php5/ext/JavaBridge.jar; file:c:/path/to/my/file.jar;
file:c:/path/to/my/second/file.jar";
java_require($javaLibs);
If you want to use class files instead of jar files then put the class files in one of the classpath directories. But you have to put them in a directory structure that matches the packages of the classes.
Example:
In your case you have C:\javaclasses in your classpath. If one of your classes (named "myClass") is in package com.paulr.projects.phpproject1 then make sure to copy the class file to C:\javaclasses\com\paulr\projects\phpproject1 and then do this:
$myClass = new Java("com.paulr.projects.phpproject1.myClass");
But the first step is to test the script I posted. I hope I didn't make things too complicated.
Thomas
Wow! That is good that you reproduced the problem. but it looks like a major change which I am about to try out. First, do you recommend uninstalling the old php and its pecl, as well as Apache and MySQL ??
Paul
This is what I did:
I just stopped apache and renamed the complete php directory. Then I extracted the new php and pecl packages so that the php directory was the same like before (I think you may need to copy the pear stuff if you installed additional pear packages). You don't need to reinstall apache, mysql or any other software (just php). Copy the additional dlls that come with the new php version over the old dlls (php5ts.dll, libmysql.dll, libmash.dll ... just any dlls that you copied to system32. In my case I copied that additional dlls into the apache bin directory so that I didn't have to mess around with the system32 directory).
Just completely replace the old php installation (but not the php.ini) with the new one and follow the additional steps in my last post.
Thomas
I will go forward with this (with great courage) tomorrow, and let you know if I reach friendly shores.
Paul
Thomas
I got through your first step of updating php OK.
Next(step 2) you say to download php/java bridge. Where is this download located. What is the title of it? I think I need a little more detail here.
Thanks,
Paul
The link was in my last big post (but a little hard to find):
http://php-java-bridge.sourceforge.net/
There's a download link near the bottom of the page ("Installation instructions"). It's a link to sourceforge.net where you can download php-java-bridge_3.1.4_j2ee.zip. That zip file contains the .war file I was writing about.
Thomas