从本地Java调用本地php脚本的最佳方法? [英] Best way to call a local php script from a local java?

查看:261
本文介绍了从本地Java调用本地php脚本的最佳方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从JAVA调用PHP脚本的最佳方法是哪一种?我现在使用下一个代码调用PHP可执行文件:

Which one is the best way to call a PHP script from JAVA? I'm calling now the PHP executable using the next code:

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可执行文件会消耗资源. Java SAPI或类似的将php模块加载到Java中呢?

But loading and disposing the php executable consumes resources. What about Java SAPI or something like loading a php module into java?

我正在调用"exec.execute(command);"循环内.

I'm calling the "exec.execute(command);" inside a loop.

推荐答案

如果您真的想从Java使用系统上的本机php,则可以尝试以下 Java到php示例代码可能会有所帮助.

If you really want to use the native php on the system from java, you can try this PHP/Java Bridge. It claims to be faster and more efficient than just shelling out to php. It also appears to be able to call from Java to php or php to java in web and desktop applications. This Java to php example code might be helpful.

这篇关于从本地Java调用本地php脚本的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆