You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

236 lines
9.8 KiB

26 years ago
26 years ago
  1. What is PHP4 ext/java?
  2. PHP4 ext/java provides a simple and effective means for creating and
  3. invoking methods on Java objects from PHP. The JVM is created using JNI,
  4. and everything runs in-process.
  5. Two examples are provided, jver and jawt, to illustrate usage of this
  6. extension. A few things to note:
  7. 1) new Java() will create an instance of a class if a suitable constructor
  8. is available. If no parameters are passed and the default constructor
  9. is useful as it provides access to classes like "java.lang.System"
  10. which expose most of their functionallity through static methods.
  11. 2) Accessing a member of an instance will first look for bean properties
  12. then public fields. In other words, "print $date.time" will first
  13. attempt to be resolved as "$date.getTime()", then as "$date.time";
  14. 3) Both static and instance members can be accessed on an object with
  15. the same syntax. Furthermore, if the java object is of type
  16. "java.lang.Class", then static members
  17. 4) Exceptions raised result in PHP warnings, and null results. The
  18. warnings may be eliminated by prefixing the method call with an
  19. "@" sign. The following APIs may be used to retrieve and reset
  20. the last error:
  21. java_last_exception_get()
  22. java_last_exception_clear()
  23. 5) Overload resolution is in general a hard problem given the
  24. differences in types between the two languages. The PHP Java
  25. extension employs a simple, but fairly effective, metric for
  26. determining which overload is the best match.
  27. Additionally, method names in PHP are not case sensitive, potentially
  28. increasing the number of overloads to select from.
  29. Once a method is selected, the parameters are cooerced if necessary,
  30. possibly with a loss of data (example: double precision floating point
  31. numbers will be converted to boolean).
  32. 6) In the tradition of PHP, arrays and hashtables may pretty much
  33. be used interchangably. Note that hashtables in PHP may only be
  34. indexed by integers or strings; and that arrays of primitive types
  35. in Java can not be sparse. Also note that these constructs are
  36. passed by value, so may be expensive in terms of memory and time.
  37. Build and execution instructions:
  38. Given the number of platforms and providers of JVMs, no single set of
  39. instructions will be able to cover all cases. So in place of hard and
  40. fast instructions, below are a working examples for a number of free and
  41. commercial implementations and platforms. Please adjust the paths to
  42. suit your installation. Also, if you happen to get this to work on
  43. another JVM/platform combination, please let me know, particularly if
  44. a unique build or execution setup was required.
  45. Note for Windows users: semi-colons (";") mark the beginning of
  46. comments in php.ini files, so if you wish to add to the classpath,
  47. make sure that the entire string is in quotes. See the JDK 1.1.8
  48. instructions below for an example.
  49. This function has been tested in both CGI and Apache (apxs) modes. As
  50. the current design requires shared libraries, this support can not be
  51. linked statically into Apache.
  52. With ext/java, no Java Virtual Machines are created until the first
  53. Java call is made. This not only eliminates unnecessary overhead if
  54. the extension is never used, it also provides error messages directly
  55. back to the user instead of being burried in a log some place.
  56. For people interested in robustness, performance, and more complete
  57. integration with Java, consider using the sapi/servlet interface which
  58. is built upon the Java extension. Running PHP as a servlet enables PHP
  59. to utilize the existing JVM and threads from the servlet engine, and
  60. provides direct access to the servlet request and response objects.
  61. Finally, the bottom of this readme contains some guidance for how to
  62. approach situations in which these instructions don't work on your
  63. machine.
  64. ========================================================================
  65. === JVM=Kaffe 1.0.4 (as delivered with OS), OS=Redhat Linux 6.1 ===
  66. ========================================================================
  67. build instructions:
  68. ./configure --with-java
  69. php.ini:
  70. [java]
  71. java.library.path=/usr/lib/kaffe:/home/rubys/php4/modules
  72. java.class.path=/usr/share/kaffe/Klasses.jar:/home/rubys/php4/modules/php_java.jar
  73. extension_dir=/home/rubys/php4/modules
  74. extension=libphp_java.so
  75. ========================================================================
  76. === JVM=Kaffe 1.0.5 (built from source), OS=Redhat Linux 6.1 ===
  77. ========================================================================
  78. build instructions:
  79. ./configure --with-java
  80. php.ini:
  81. [java]
  82. java.library.path=/usr/local/lib/kaffe:/home/rubys/php4/modules
  83. java.class.path=/usr/local/share/kaffe/Klasses.jar:/home/rubys/php4/modules/php_java.jar
  84. extension_dir=/home/rubys/php4/modules
  85. extension=libphp_java.so
  86. ========================================================================
  87. === JVM=IBM 1.1.8, OS=Redhat Linux 6.1 ===
  88. ========================================================================
  89. build instructions:
  90. ./configure --with-java
  91. php.ini:
  92. [java]
  93. java.class.path=/home/jdk118/lib/classes.zip:/home/rubys/php4/modules/php_java.jar
  94. extension_dir=/home/rubys/php4/modules
  95. extension=libphp_java.so
  96. ========================================================================
  97. === JVM=Blackdown 1.2.2 RC4, OS=Redhat Linux 6.1 ===
  98. ========================================================================
  99. build instructions:
  100. ./configure --with-java
  101. php.ini:
  102. [java]
  103. java.class.path=/home/rubys/php4/lib/php_java.jar
  104. extension_dir=/home/rubys/php4/modules
  105. extension=libphp_java.so
  106. ========================================================================
  107. === JVM=Sun JDK 1.2.2, OS=Linux ===
  108. ========================================================================
  109. This compiler is not supported at this time. At the moment, only green
  110. threads are supported, requiring system calls to be wrapped, which is
  111. incompatible with the JNI Invocation API. Once native threads are
  112. supported, It is expected that the configuration will be identical to
  113. the Blackdown JDK.
  114. ========================================================================
  115. === JVM=Sun JDK 1.1.8, OS=Windows NT 4 ===
  116. ========================================================================
  117. build instructions:
  118. SET JAVA_HOME=D:\jdk1.1.8
  119. msdev ext\java\java.dsp /MAKE "java - Win32 Debug_TS"
  120. php.ini:
  121. [java]
  122. java.class.path="D:\jdk1.1.8\lib\classes.zip;F:\PHP4\Debug_TS\php_java.jar"
  123. extension=php_java.dll
  124. ========================================================================
  125. === JVM=Sun JDK 1.2.2, OS=Windows NT 4 ===
  126. ========================================================================
  127. build instructions:
  128. SET JAVA_HOME=D:\jdk1.2.2
  129. msdev ext\java\java.dsp /MAKE "java - Win32 Debug_TS"
  130. php.ini:
  131. [java]
  132. java.class.path=F:\PHP4\Debug_TS\php_java.jar
  133. extension=php_java.dll
  134. =========================================================================
  135. Guidance for when these instructions don't work.
  136. JDK vendors don't typically document their internal workings, and are
  137. typically very reliant on code inside of the JAVA main program and the
  138. installation directory structure. For this reason, running PHP as a
  139. servlet is typically much easier to get working. But if for some reason
  140. this is not appropriate for you, and the instructions above don't work,
  141. then read on.
  142. The first thing to realize is that the directory structure of the JDK is
  143. very important. Some users (particularly on Windows) get a message about
  144. a DLL or shared library not being available and proceed to find that file
  145. and copy it into a system directory. This typically just gets you to the
  146. next problem - for example, it appears that many JDKs attempt to locate
  147. the runtime Java classes (rt.jar) in a directory relative to these system
  148. libraries. So unless you are inclined to copy your entire Java
  149. installation, you are much better adjusting your PATHs.
  150. Not documented above, but useful for many JDK's is ability to specify the
  151. library path via java.library.path in the php.ini. On many Unix machines,
  152. determining the initial value for this can be done by changing directory
  153. to where you find a shared library that can't be loaded (example:
  154. libjava.so), and executing "ld libjava.so". If you see some modules
  155. listed as "not found", add the necessary directories to LD_LIBRARY_PATH
  156. and repeat until successful. On my system, I require the following
  157. two directories.
  158. /home/jdk1.2.2/jre/lib/i386/native_threads
  159. /home/jdk1.2.2/jre/lib/i386/classic
  160. Note: this only determines the statically loaded libraries. Additional
  161. libraries (such as libzip.so) may be loaded dynamically. On my system,
  162. libzip.so is located in
  163. /home/jdk1.2.2/jre/lib/i386
  164. Another php.ini variable which may be helpful is java.home.
  165. If java.library.path doesn't work for you (it won't on any JDK 1.1
  166. implementations, for example), then try setting the system PATH or the
  167. LD_LIBRARY_PATH before starting your web server. For Apache on Linux
  168. systems, this can be accomplished by editing the Root's .bashrc and
  169. adding the necessary export LD_LIBRARY_PATH statement.
  170. If that doesn't work, try dividing an (hopefully) conquering by temporarily
  171. eliminating items such as Apache from the process by adjusting the
  172. arguments passed to the ./configure command (i.e., removing --with-apxs).
  173. If all else fails, "man dlopen" on Unix systems will give more insight on
  174. what the system is trying to do internally.