Hi,
> installed the Bridge on my Windows machine. I wrote PHP script that calls Java code using the
> DYNAMIC LOAD method.
I assume you mean the DynamicClassLoader. (DynamicLoad may also mean that you start the bridge
and the JVM as a sub component for each incoming request).
> It works but the web page that contains the PHP script loads very slowly
> (15-20 seconds) the first time, but a bit faster the succeeding times (5 seconds).
5 seconds is too slow. This may mean that you are starting a new JVM for each invocation.
Do you start Java as a sub component of apache or IIS or as a separate component, for example
via the Tomcat servlet engine?
> What the Java code does is supposedly simple, it reads a short string value from a relational
> database, and passes it to PHP script to display. Oh, but the Java code requires a lot of
> libraries like log4j, dom4j, asm, xom, etc. (more than 20 of them).
Does't matter, the DynamicClassLoader caches them.
> What happens exactly with "dynamic loading"? Is the sequence of events below accurate?
[depends on what you mean with "dynamic loading".
> 1) User requests for a web page that contains a PHP script that calls Java code.
Apache/IIS keeps a pool of PHP instances. When the client browser requests a PHP page, the
web server activates the PHP instance and passes it the script. The PHP/Java Bridge creates
an XML document from the script and forwards it to the Java VM (usually started via a local
Servlet Engine).
> 2) The system loads all Java base classes (libraries).
When your script contains a java_require(...) call, the DynamicClassLoader resolves and loads
the Java libraries and caches them.
> 3) The system loads the Java Virtual Machine (JVM).
Only if the JVM is running as a sub component of Apache or IIS and if Apache or IIS cannot
maintain a pool of PHP instances, which is usually the case with CGI.
> 4) The system loads all Java libraries needed by the PHP script.
Only if the JVM is running as a sub component or Apache/IIS and PHP is running in CGI mode.
> What happens exactly with "static loading"? Is this sequence of events accurate?
>
> 0) User starts up the welcome page of a web application.
> The system loads all Java base classes (libraries) AND
> the Java Virtual Machine (JVM).
Well, the JVM is usually started as a separate component. Or in the MINIT method invoked during
the startup of Apache or IIS. This means that one VM is usually attached to the web server.
The only exception are CGI or console scripts. If you use the C implementation, it will start
a new JVM for each invocation. If you use the PHP implementation, it will throw an error if no
persistent JVM is running on the given port#.
Regards,
Jost Boekemeier
dddd
|