dev@grizzly.java.net

[OT] Basic JNI questions/PHP implementation

From: Jeanfrancois Arcand <Jeanfrancois.Arcand_at_Sun.COM>
Date: Wed, 23 Jan 2008 20:24:12 -0500

Hi,

I'm currently working on a PHP's Grizzly extension via the
com.sun.grizzly.Adapter class, and today I've hit a wall :-). What I
want to do is:

Client --> Request --> Grizzly --> PHPAdapter -- JNI Call --> libphp5.so

Inside the PHPAdapter, I did:

> static {
> System.loadLibrary("php5");
> }

so far so good. Now problems :-) Since I'm working on linux, I need to
build the libphp5.so from scratch. So I've followed the instruction
(many many many times ;-) by building Apache2 from scratch, and then
build php 5 using Apache 2. At the end, I'm getting the libphp5.so,
which is what I need. Then, I start Grizzly HTTP Server with:

% java -Djava.library.path=/usr/local/apache2/lib/ -jar
grizzly-http-1.7-SNAPSHOT.jar 8080 /www/php

And *always* get:

> java.lang.UnsatisfiedLinkError: /usr/local/apache2/modules/libphp5.so: /usr/local/apache2/modules/libphp5.so: undefined symbol: ap_rwrite
> at java.lang.ClassLoader$NativeLibrary.load(Native Method)
> at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1751)
> at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1676)
> at java.lang.Runtime.loadLibrary0(Runtime.java:822)
> at java.lang.System.loadLibrary(System.java:993)

Which is expected, because:

> [jfarcand_at_localhost http]$ ldd -r /usr/local/apache2/modules/libphp5.so
> linux-gate.so.1 => (0x00546000)
> libcrypt.so.1 => /lib/libcrypt.so.1 (0x00ae6000)
> librt.so.1 => /lib/librt.so.1 (0x00111000)
> libz.so.1 => /usr/lib/libz.so.1 (0x00125000)
> libresolv.so.2 => /lib/libresolv.so.2 (0x00164000)
> libm.so.6 => /lib/libm.so.6 (0x00177000)
> libdl.so.2 => /lib/libdl.so.2 (0x00f4d000)
> libnsl.so.1 => /lib/libnsl.so.1 (0x00b6c000)
> libxml2.so.2 => /usr/lib/libxml2.so.2 (0x00e21000)
> libc.so.6 => /lib/libc.so.6 (0x001af000)
> libpthread.so.0 => /lib/libpthread.so.0 (0x0019b000)
> /lib/ld-linux.so.2 (0x00148000)
> undefined symbol: ap_rwrite (/usr/local/apache2/modules/libphp5.so)
> undefined symbol: apr_table_set (/usr/local/apache2/modules/libphp5.so)
[cut ... more than 20]

Now the ap_* stuff is from Apache2, which is probably dynamically loaded
when Apache2 start. Now how can I make sure the libph5.so gets all its
dependencies loaded from java? I did try to add the path to Apache 2
*.so file to my -Djava.library.path but still get the same exceptions. I
did build the libphp5.so on two linux kernel and os X, and always get
the same exception.

I'm probably missing something trivial :-) Any help appreciated :-)

Thanks

-- Jeanfrancois