From: <php...@li...> - 2010-10-26 00:15:19
|
Hi all, I'm hoping someone can help me out with a problem I've been having. My aim is as follows: 1) browse to a page generated by a php script. This script starts the javabridge in the background like this: $port = 9200; $javaHosts = "localhost:" . $port; define("JAVA_HOSTS", $javaHosts); // define engine scope define("ENGINE_SCOPE", 100); // require Java.inc for handling JAVA/PHP bridge related matters require_once ("Java.inc"); $basePath = dirname($_SERVER["SCRIPT_FILENAME"]); $port = 9200; // check if bridge is running already if (!$file = @fsockopen("127.0.0.1", $port, $errno, $errstr, 2)) { // not running, so start bridge $baseCmd = "java -Dphp.java.bridge.base=" . $basePath . "/lib/javabridge -jar " . $basePath . "/lib/javabridge/JavaBridge.jar SERVLET_LOCAL:"; $endCmd = " 3 " . $basePath . "/lib/javabridge/JavaBridge.log"; $cmd = $baseCmd . $port . $endCmd; } 2) create a java class object through the bridge, e.g: $myobject = new java("myclass"); 3) store this in the java context so I can access this object again after the script is renewed. For that I am trying this: define("ENGINE_SCOPE", 100); java_context()->setAttribute("myobject", $myobject, ENGINE_SCOPE); 4) and then getting the object out again in the new script with: $myobject = java_values(java_context()->getAttribute("myobject")); But trying to access the java context after I started up the bridge gives me: *Warning*: fread() [function.fread <http://localhost/mmic/function.fread>]: Length parameter must be greater than 0 in * C:\MyPrograms\wamp\www\mmic\java\Java.inc* on line *1157* protocol error: , Invalid document end at col 1. Check the back end log for OutOfMemoryErrors. fread() [function.fread<http://localhost/mmic/function.fread>]: Length parameter must be greater than 0 With the backend log stating: Oct 25 17:11:09 JavaBridge ERROR: An exception occured: java.lang.IllegalStateException: Please use a JEE server or servlet engine. java.lang.IllegalStateException: Please use a JEE server or servlet engine. at php.java.bridge.JavaBridgeRunner.doPut(JavaBridgeRunner.java:198) at php.java.bridge.http.HttpServer.service(HttpServer.java:289) at php.java.bridge.http.HttpServer$Runner.run(HttpServer.java:205) at php.java.bridge.ThreadPool$Delegate.run(ThreadPool.java:60) So clearly this is not the way for me to accomplish what I want to accomplish. So my question is, what would be the correct way to keep a java object created in php from one php script execution to another? Thanks a lot in advance for any insights, suggestions! Bart |