Integrating BIRT with PHP

BIRT(Business Intelligence and Reporting Tools)是以Eclipse為基礎的開源報表系統,可整合Java/J2EE應用程式。目前的版本2.5,穩定通用的版本為2.3.2,已經比我剛開始用的時候又進展了許多。

當時研究BIRT是希望解決PHP應用程式的報表輸出(而且要免費),在藍鯨平台架構下,使用程式產出報表輸出較不直覺,希望透過整合第三方報表工具來加速開發。坦白說一般企業內寫得報表不怎美觀,MIS人員既要維護又要開發,樣式美化這件事心有餘力不足呀!

在BIRT 2.1版時,整合PHP使用的是網址列(BIRT Viewer URLs)的方式,也就是將BIRT Viewer佈署到Tomcat之類的應用伺服器,PHP程式將報表檢視網址嵌進來或是轉址即可,可說是相當簡單。如果要傳遞參數,同樣需要透過網址,換句話說是GET。

然而新的方法使用PHP/Java Bridge,可以讓PHP直接呼叫Java類別庫,將輸出直接送回php所在頁面,可以擁有較多的控制。只不過安裝指引實在有點過於簡單,特別是FastCGI的部份,只能說我對PHP運行環境還是一知半解。

我的環境:

  • Windows XP Professional SP3
  • Apache 2.2.14
  • PHP 5.3.1 VC9 Thread Safe
  • Tomcat 5.5.28
  • Microsoft Visual C++ 2008 Redistributable – x86 9.0.30729.17

光是Apache與PHP的組合就已經讓我反覆試了很久,PHP 5.3.1下載時特別注意VC9是使用Visual Studio 2008編譯而成,因此作業系統要記得安裝Microsoft 2008 C++ Runtime,奇怪的是,一旦已經先安裝了C++ Runtime再安裝VC6版本就無法正常啟動Apache。最後我還是沒有將Apache設定為CGI模式,那樣PHP必須使用VC9 Non Thread Safe版本,但至少已經可以在php網頁中呼叫BIRT報表了!

由於我是windows環境,因此下載 php-java-bridge_5.5.4.1_documentation.zip,解開後的檔案結構如下,將JavaBridge.war丟到Tomcat目錄中的webapps就會自動解開,解開的JavaBridge資料夾複製到Apache文件目錄下即可,值得注意的是JavaBridge.war內含了一個PHP CGI運行環境(JavaBridge\WEB-INF\cgi),如果執行test.php,你會發現php版本為5.2.1。JavaBridge PHP CGI version

  • documentation (+)
  • MONO+NET.STATNALONE (+)
  • JavaBridge.war

瀏覽 http://localhost:8080/JavaBridge 與 http://localhost/JavaBridge,如果沒有錯誤丟出,就表示安裝成功。特別是Report Generator,可以知道Viewer是否安裝正確。這同時隱含JavaBridge.war包含了BIRT runtime類別庫。

birt example

BIRT example

實際的撰寫範例在此暫時不多敘述,theserverside上的文件已經寫得很清楚,如果缺少報表範例檔,可以在官網下載。

reference

  • http://www.theserverside.com/tt/articles/article.tss?l=IntegratingBIRTwithPHP
  • http://eclipse.org/birt/phoenix/deploy/usingPHP.php
  • http://eclipse.org/birt/phoenix/examples/solution/

Error Message

javax.servlet.ServletException: PHP FastCGI server failed, switching off FastCGI SAPI.
php.java.servlet.fastcgi.FastCGIServlet$CGIRunner.execute(FastCGIServlet.java:417)
php.java.servlet.CGIServlet.handle(CGIServlet.java:401)
php.java.servlet.PhpCGIServlet.handle(PhpCGIServlet.java:427)
php.java.servlet.CGIServlet.doGet(CGIServlet.java:474)
javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

php.java.servlet.fastcgi.ConnectException
	php.java.servlet.fastcgi.NPChannelFactory.doConnect(NPChannelFactory.java:50)
	php.java.servlet.fastcgi.NPChannelFactory.connect(NPChannelFactory.java:54)
	php.java.servlet.fastcgi.FastCGIServlet$1.connect(FastCGIServlet.java:159)
	php.java.servlet.fastcgi.ConnectionPool$Connection.reopen(ConnectionPool.java:101)
	php.java.servlet.fastcgi.ConnectionPool.openConnection(ConnectionPool.java:200)
	php.java.servlet.fastcgi.FastCGIServlet$CGIRunner.parseBody(FastCGIServlet.java:445)
	php.java.servlet.fastcgi.FastCGIServlet$CGIRunner.doExecute(FastCGIServlet.java:402)
	php.java.servlet.fastcgi.FastCGIServlet$CGIRunner.execute(FastCGIServlet.java:410)
	php.java.servlet.CGIServlet.handle(CGIServlet.java:401)
	php.java.servlet.PhpCGIServlet.handle(PhpCGIServlet.java:427)
	php.java.servlet.CGIServlet.doGet(CGIServlet.java:474)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

java.io.FileNotFoundException: \\.\pipe\C:\Application\Tomcat55\temp\JavaBridge1726915862995039812.socket (所有的管道例項都在使用中。)
java.io.RandomAccessFile.open(Native Method)
java.io.RandomAccessFile.<init>(Unknown Source)
java.io.RandomAccessFile.<init>(Unknown Source)
php.java.servlet.fastcgi.NPChannelFactory.doConnect(NPChannelFactory.java:48)
php.java.servlet.fastcgi.NPChannelFactory.connect(NPChannelFactory.java:54)
php.java.servlet.fastcgi.FastCGIServlet$1.connect(FastCGIServlet.java:159)
php.java.servlet.fastcgi.ConnectionPool$Connection.reopen(ConnectionPool.java:101)
php.java.servlet.fastcgi.ConnectionPool.openConnection(ConnectionPool.java:200)
php.java.servlet.fastcgi.FastCGIServlet$CGIRunner.parseBody(FastCGIServlet.java:445)
php.java.servlet.fastcgi.FastCGIServlet$CGIRunner.doExecute(FastCGIServlet.java:402)
php.java.servlet.fastcgi.FastCGIServlet$CGIRunner.execute(FastCGIServlet.java:410)
php.java.servlet.CGIServlet.handle(CGIServlet.java:401)
php.java.servlet.PhpCGIServlet.handle(PhpCGIServlet.java:427)
php.java.servlet.CGIServlet.doGet(CGIServlet.java:474)
javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

About Boss Yang

I come from Taiwan.
This entry was posted in IT and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre user="" computer="" escaped="">