从 PHP exec 调用 java [英] Calling java from PHP exec

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

问题描述

我在 PHP 中执行以下操作:

I am doing the following in PHP:

exec('java -jar "/opt/flex3/lib/mxmlc.jar" +flexlib "/opt/flex3/frameworks" MyAS3App.as -default-size 360 280 -output MyAS3App.swf');

当我从命令行运行它时,它运行良好并在一两秒钟内完成.

When I run this from the command line, it runs fine and finishes in a second or two.

当我从 PHP exec 运行这个命令时,java 进程占用了 100% 的 CPU 并且永远不会返回.

When I run this command from PHP exec, the java process takes 100% CPU and never returns.

有什么想法吗?

我也尝试过使用/usr/bin/java -Djava.awt.headless=true"运行上述命令.

I have also tried running the above command with '/usr/bin/java -Djava.awt.headless=true'.

我运行的是 Mac OS X 10.5.5、MAMP 1.7、PHP 5.2.5

I am running Mac OS X 10.5.5, MAMP 1.7, PHP 5.2.5

推荐答案

原来这是一个特定于 PHP 堆栈 MAMP 的错误 (http://www.mamp.info/).

Turns out it was a bug specific to the PHP stack MAMP (http://www.mamp.info/).

结果是在 MAMP 下对 JVM 的任何调用都失败了,例如:

Turns out any invocation of the JVM following fails under MAMP, e.g.:

exec('java -version');

解决方法是在命令前加上

The fix is to prefix the command with

export DYLD_LIBRARY_PATH="";

我也意识到没有理由使用调用 mxmlc 的方法.

Also I realized there's no reason to use that method of invoking mxmlc.

这是最终的有效命令:

exec('export DYLD_LIBRARY_PATH=""; mxmlc MyAS3App.as -default-size 360 280 -output MyAS3App.swf');

这篇关于从 PHP exec 调用 java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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