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.

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