从本地java调用本地php脚本的最佳方法?
从JAVA调用PHP脚本的最佳方法是哪一种?我现在使用下面的代码调用PHP可执行文件:从本地java调用本地php脚本的最佳方法?,java,php,exec,Java,Php,Exec,从JAVA调用PHP脚本的最佳方法是哪一种?我现在使用下面的代码调用PHP可执行文件: CommandLine command = new CommandLine("php"); command.addArgument("file.php"); DefaultExecutor exec = new DefaultExecutor(); PumpStreamHandler streamHandler = new PumpStreamHandler(null, null); exec.setSt
CommandLine command = new CommandLine("php");
command.addArgument("file.php");
DefaultExecutor exec = new DefaultExecutor();
PumpStreamHandler streamHandler = new PumpStreamHandler(null, null);
exec.setStreamHandler(streamHandler);
int execute = exec.execute(command);
但是加载和处理php可执行文件会消耗资源。那么JavaSAPI或者类似于将php模块加载到Java中的东西呢
我在一个循环中调用“exec.execute(command);”。我自己从未尝试过,但似乎实际上有一个用Java编写的PHP解释器,所以您可以直接从Java程序运行PHP代码(有点像JRuby)
如果您真的想在java系统上使用本机php,可以试试这个。它声称比仅仅使用php更快、更高效。它似乎还能够在web和桌面应用程序中从Java调用php或从php调用Java。这可能会有帮助。通过,您可以使整个PHP处理器作为servlet运行。这似乎是一个各种问题和答案的重复,包括: