在windows下编译Php_Java_Bridge for php4/apache2

38 篇文章 0 订阅

PJB可以实现java+php的无缝整合,所谓鱼翅和熊掌均可兼得。不过,官方的发布的版本中windows版本只有for php 5的,对于我来说,短期内不会迁移到php5上,于是,如何编译就成为一个棘手的问题,以前没有在windows下编译过php4,昨晚摸索了半天终于编译成功了,下面是过程:
1. 下载 mingw.exe
(http://prdownloads.sourceforge.n ... 4.1.0.exe?download) --
这是安装程序,运行并安装到默认目录c:/mingw.
install current/full version of core, compilers, utilities (不需要sources)
完成后,将c:/mingw/bin加入到windows path路径,检验:
start->run->cmd
gcc -v

2. download and run msys.exe (msys是cygwin的一个minmal版本)
(http://prdownloads.sourceforge.n ... .0.10.exe?download) --
install to c:/msys/1.0 directory
修改 c:/msys/1.0/etc/fstab ,add the following line:
c:/src        /src
c:/apps/jrockit15  /java   {make sure this is the path to your j2sdk} --


3. download and run msys-dtk (这是gcc等工具的msys集合)
(http://prdownloads.sourceforge.n ... 1.0.1.exe?download)

4. download the php source (我的为4.3.11 )
and install to a directory (c:/src/php-4.3.11)

5. download the win32build.zip (这是php build的需要库和工具)
(http://www.php.net/extra/win32build.zip) and install to a directory
(c:/src/win32build)
copy win32build/bin下的文件到c:/mingw/bin,否则下面的php的configure无法运行

6. 在 win32build/include创建几个空文件,为了避免#include找不到文件:
/sys/poll.h
/sys/wait.h

7. download the javabridge source (tar.bz2 版本);
解压到php-4.3.11/ext/java 目录下(原来的内容删除)

8. Update the "m4_include" paths in
      ext/java/config.m4 将目录以 "ext/java/"开始; e.g.:
       m4_include(ext/java/tests.m4/function_checks.m4)

9. 打开 msys window (C:/msys/1.0/msys.bat)(或双击桌面上的msys图标)
cd /src/php-4.3.11
./buildconf --force (会有一些警告,不用理会)
./configure

10. Edit the php source for the following:
in php-4.3.11/main/win95nt.h 注释下列几行代码 (add // in
front of each line):
#include <io.h>
typedef unsigned int uint;
typedef unsigned long ulong;
typedef long pid_t;

in php-4.3.11/tsrm/tsrm_virtual_cwd.h 注释下列几行代码  (add
// in front of each line):
typedef unsigned short mode_t;

in php-4.3.11/tsrm/tsrm_config.w32.h 注释下列几行代码  (add //
in front of each line):
#include <crtdbg.h>


10. 创建一个build.bat文件到ext/java目录中:
<code>
set BRIDGE_VERSION=3.1.7
set PHP_JAVA=
set COND_GCJ=0
set EXTENSION_NAME=JAVA
set PHP_JAVA_BIN=javaw
set EXTENSION_DIR=../..
set PHP=../..

set SYS_INCLUDE=../../../win32build/include
set SYS_INCLUDE2=c:/mingw/include
set SYS_WIN32=../../win32


set PHPTS="../../../php-4.3.11/php4ts/php4ts"
set GCC=c:/mingw/bin/mingw32-gcc.exe
sed "s*@PHP_JAVA@*%PHP_JAVA%*;s*@COND_GCJ@*%COND_GCJ%*;s*@PHP_JAVA_BIN@*%PHP_JAVA_BIN%*;s*@EXTENSION@*%EXTENSION_NAME%*;s*@BRIDGE_VERSION@*%BRIDGE_VERSION%*" <./init_cfg.c.in >./init_cfg.c
sed "s*@PHP_JAVA@*%PHP_JAVA%*;s*@COND_GCJ@*%COND_GCJ%*;s*@PHP_JAVA_BIN@*%PHP_JAVA_BIN%*;s*@EXTENSION@*%EXTENSION_NAME%*;s*@BRIDGE_VERSION@*%BRIDGE_VERSION%*" <./init_cfg.h.in >./init_cfg.h
rm *.o
%GCC% -w -I%SYS_INCLUDE% -I%SYS_INCLUDE2% -I. -I%SYS_WIN32% -I%PHP% -I%PHP%/main -I%PHP%/Zend -I%PHP%/TSRM  -D"ZEND_DEBUG=0"  -D"TSRM_EXPORTS" -D"LIBZEND_EXPORTS" -D"ZTS" -D"_MBCS"  -DCOMPILE_DL_JAVA -DPHP_WIN32 -DZEND_WIN32 -DCFG_JAVA_SOCKET_INET -D__MINGW__ -DWIN32 -DEXTENSION_DIR=/"%EXTENSION_DIR%/" -c *.c
dllwrap  --export-all-symbols -k  *.o -L%PHP% -l%PHPTS% -lws2_32 -o php_java_bridge.dll
</code>
11. 在文件管理器中双击build.bat,开始编译,并生成一个php_java_bridge.dll

12. copy the php_java.dll 到其它php extensions的目录下...(in my case c:/apps/php-4.3.11/extensions

13. Edit and add to php.ini(c:/windows/php.ini):
<code>
;;start php.ini addendum
[javabridge]
extension = php_java.dll


;; log level between 0 (log off) and 4 (log debug). The default "log
;; file" is the standard output. The default level is 2.

java.log_level=3


;; If you don't have a servlet engine, double-click on JavaBridge.jar
;; to start the backend and uncomment the following option.

java.socketname=9267


;; If you have a servlet engine or an application server, deploy
;; JavaBridge.war and re-start the servlet engine or the application
;; server. Comment out the "java.socketname" option and uncomment
;; the following options.

;java.hosts="127.0.0.1:8080"
;java.servlet=On
</code>
上面是一个简单的配置,用于独立运行,适合测试,具体product环境的部署方式参考pjb的README。

14. 重起服务器,运行一个<?phpinfo();?> php 文件,如果看到java extension,就说明成功了。
15. 剩下的就可以按照pjb的readme文档,修改和使用其运行方式了。
通过PJB,我在CRM中使用Lucene作为一个核心,实现复杂的全文检索和预搜索(避免一些关系数据库无法实现的瓶颈),同时使用了mq实现一些异步事件模型,php负责view,一些复杂的工作交由java
应用完成,这样开发效率达到最高。
另外,还是觉得php在linux下面的编译最简单,phpize就搞定,仿真unix的cygwin/msys都会有这样那样的问题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值