From: <php...@li...> - 2006-08-27 14:23:24
|
Hi, > So my question is - how do I decide what are the > latest and greatest > versions of php/apache that will work? well, the PHP/Java Bridge is only the XML protocol, as such it should run with any PHP version >= 4.3.2. I.e with any PHP version which has a working version of fsockopen. We publish PECL and PEAR extensions for convenience, but these extensions aren't necessary to call out to Java libraries. The following example demonstrates how easy it is to call out to Java libraries with nothing but fsockopen, fread and fwrite: <? class Protocol { var $c; function __construct() { $this->c=fsockopen("127.0.0.1",9267); fwrite($this->c, chr(0100)); // mode 0 0, see PROTOCOL.TXT } function createBegin($s) { fwrite($this->c,sprintf("<C v=\"%s\" p=\"I\">", $s)); } function createEnd() { fwrite($this->c, "</C>"); } function invokeBegin($o, $m) { fwrite($this->c, sprintf("<I v=\"%d\" m=\"%s\" p=\"I\">", $o, $m)); } function invokeEnd() { fwrite($this->c, "</I>"); } function writeString($s) { fwrite($this->c, sprintf("<S v=\"%s\"/>", $s)); } function writeInt($s) { $p="O"; if($s<0) { $p="A"; $s*=-1; } fwrite($this->c, sprintf("<L v=\"%d\" p=\"%s\"/>", $s, $p)); } function writeObject($s) { fwrite($this->c, sprintf("<O v=\"%d\"/>", $s->java)); } function writeVal($s) { if(is_string($s)) { $this->writeString($s); } else if(is_int($s)) { $this->writeInt($s); } else { $this->writeObject($s); } } function getResult() { $res = fread($this->c, 8192); $ar = sscanf($res, "%s v=\"%s"); return substr($ar[1], 0, strpos($ar[1], "\"")); } } function getProtocol() { static $protocol; if(!isset($protocol)) $protocol=new Protocol(); return $protocol; } class J/*ava*/ { var $java; function __construct() { if(!func_num_args()) return; $protocol=getProtocol(); $ar = func_get_args(); $protocol->createBegin(array_shift($ar)); foreach($ar as $arg) { $protocol->writeVal($arg); } $protocol->createEnd(); $ar = sscanf($protocol->getResult(), "%d"); $this->java=$ar[0]; } function __call($method, $args) { $protocol=getProtocol(); $protocol->invokeBegin($this->java, $method); foreach($args as $arg) { $protocol->writeVal($arg); } $protocol->invokeEnd(); $proxy = new J(); $ar = sscanf($protocol->getResult(), "%d"); $proxy->java=$ar[0]; return $proxy; } function toString() { $protocol=getProtocol(); $protocol->invokeBegin("", "castToString"); $protocol->writeVal($this); $protocol->invokeEnd(); return $protocol->getResult(); } } // Test $i1 = new J("java.math.BigInteger", "1", 2); $i2 = new J("java.math.BigInteger", "11", 2); $i3 = $i1->add($i2); echo $i3->toString() . "\n"; ?> To run the above example start the JavaBridge.jar, for example by double-clicking on it or with: java -jar JavaBridge.jar INET:0 4 JavaBridge.log Regards, Jost Boekemeier ___________________________________________________________ Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de |