java 调php脚本,从本地Java调用本地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);

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

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

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值