|
From: <php...@li...> - 2008-10-25 17:44:24
|
> I think the best option is to start Apache, capture a PHP
> process from Apache and call into a continuation of that
> process.
Here's a solution I've whipped together; the EngineFactory now accepts two more arguments, a protocol and a port number. If the HTTP server document root contains a copy of the web application, you can now invoke PHP libraries deployed into Apache of IIS using the JSR 223 API:
<%!
/* Create a PHP script with a function f() */
private static java.io.File script;
private static java.io.File getScript(String path) {
if(script!=null) return script;
return script=EngineFactory.getPhpScript(path, new StringReader(
"<?php function f($arg) {return 1 + (int)(string)$arg); }; ?>"));
}
%>
<%
/* Create a standard script engine and invoke function f on http port 80 */
ScriptEngine e = EngineFactory.getInvocablePhpScriptEngine (this,
application, request, response, "http", 80);
File script = getScript(application.getRealPath(request.getServletPath()));
FileReader reader = EngineFactory.createPhpScriptFileReader(script);
e.eval (reader); reader.close();
Object result=((Invocable)i).invokeFunction("f",new Object[]{new Integer(2)});
e.eval ((Reader)null); // flush the output generated by invokeXXX
out.println("result from php::f(), printed from the servlet: " + result);
%>
Regards,
Jost Boekemeier
|