ID:               18600
 Comment by:       jlondon at mcg dot edu
 Reported By:      nalves at equifax dot com dot br
 Status:           Open
 Bug Type:         Java related
 Operating System: Windows 2000
 PHP Version:      4.2.3
 New Comment:

Getting the same bug.  Running Win2k Server, IIS 5, php4.2.3,
jsdk1.4.1.  I read a while back that running as a CGI would eliminate
the error so I tried that but the performance hit was too much to bear
since I only used java on one page.  Did a little more searching and
came up with a little work around.  Still not perfect but takes much
longer to crash.  

$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will
read from
   1 => array("pipe", "w"),  // stdout is a pipe that the child will
write to
   2 => array("file", "/temp/error-output.txt", "a"), // stderr is a
file to write to
);

$process = proc_open("c:\\php\\cli\\php.exe", $descriptorspec,
$pipes);
if (is_resource($process))
{
        // $pipes now looks like this:
        // 0 => writeable handle connected to child stdin
        // 1 => readable handle connected to child stdout
        // Any error output will be appended to /tmp/error-output.txt

        $size = fwrite($pipes[0], "<? \$Login = new Java('CheckLogin'); echo
\$Login->CheckLogin('" . $username . "', '" . $password . "'); ?>");
        if(!fclose($pipes[0]))
                echo "There was an error closing the pipe";

        $result = fgets($pipes[1], $size + 1);
        fclose($pipes[1]);

        // It is important that you close any pipes before calling
        // proc_close in order to avoid a deadlock
        $return_value = proc_close($process);
}

Basically what I do is create a process and send it the lines of code I
would use to create and manipulate the java classes.  The process gives
me the output and I close the process.  It works pretty well and will
extend the "restart interval" from everytime the script runs to every
couple of days.

For those out there chasing this bug, my method fails on the
$return_value = proc_close($process); line.  Once it fails it will not
work again until IIS is restarted.  Until IIS is restarted the process
fails on $result = fgets($pipes[1], $size + 1); line.  Hope you get
this one fixed.  This could be a really powerful plugin.

-Jake


Previous Comments:
------------------------------------------------------------------------

[2003-06-04 21:37:36] jason at ipedo dot com

I meet this problem too.
Why should it recreate JVM?
Since it's module, I think it need only create JVM once.
In linux environment, althoug i don't meet the error, the preformence
is bad when system recreate JVM.
How can i disable recreating the JVM or decrease the frequence of
creating JVM?

------------------------------------------------------------------------

[2003-05-27 17:36:44] dave at unicon dot net

Has anything been resolved for this usiong the non-cgi approach?

I have found something I did not see in other comments.  It seems that
I get the fatal error after a set amount of seconds.  Maybe due to some
time out?

Thanks

------------------------------------------------------------------------

[2003-05-24 07:40:55] asifrrana at hotmail dot com

Has anyone found a good (not using cgi-bin) resolution to this problem
yet? I just downloaded the latest release 4.3.2 with JDK1.4.0 on
Windows 2000 and I am still getting the same error "Fatal error: Unable
to create Java Virtual Machine"

------------------------------------------------------------------------

[2003-05-22 04:11:11] Mike at 123456 dot net

Hi everybody,

I experience the problem of the "Unable to create Java Virtual
Machine", on a Windows 2000, with easyphp, after some search, my
conclusion is that you couldn't use (for the moment) php as a module in
Apache, you must for that use it in cgi mode (I tried it and it work
fine, and change from module to cgi mode doesn't affect usage of PHP).

My configuration is :
Windows 2000
Apache 2.0.45
J2SDK 1.4.1_02
PHP 4.3.2 RC3

You must install J2SK, Apache, and then php (the tutorial indicate how
to install in cgi mode), you can go to the following adress for
installation (a very good tutorial) :

http://hotwired.lycos.com/webmonkey/00/44/index4a_page8.html?tw=programming

after that just configure you php.ini with the following values :

[Java]
extension=php_java.dll
java.home = C:\j2sdk1.4.1_02\jre\bin
java.library = C:\j2sdk1.4.1_02\jre\bin\server\jvm.dll
java.library.path = C:\php4\extensions
java.class.path = "C:\php4\extensions\php_java.jar;C:\MyClasses;"

Don't forget to affect the extension_dir value like : 

extension_dir=C:\php4\extensions

And now it's work.

------------------------------------------------------------------------

[2003-05-16 10:37:30] fj at hilab dot it

I personally have experienced the same problem with the 1.4.0_02 SDK
externally connected to php4.3.1 under Win2K.
I had very frequently the aforementioned 'Unable to create Java Virtual
Machine' error and after a number of tests I discovered that such error
never happened the first time I restarted the php engine by restarting
the Apache server.
This made me think that the JVM is left in an abnormal state after the
php interpreter exits the page.
For this reason I inserted an explicit call to the System.exit(0) at
the very end of the page and this solved all the problems! The only
side effect is that now it is mandatory to call the flush() php
function, or the page will not be completely shown...

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/18600

-- 
Edit this bug report at http://bugs.php.net/?id=18600&edit=1

Reply via email to