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

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

问题描述


$ b

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

当我从命令行运行这个命令时,它运行良好,并在一两秒内完成。 / p>

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



想法?

我也试着用'/ usr / bin / java -Djava.awt.headless = true'运行上面的命令。



我正在运行Mac OS X 10.5.5,MAMP 1.7,PHP 5.2.5 解决方案

事实证明这是一个特定于PHP堆栈MAMP的错误( http://www.mamp.info/ ) 。



原来在MAMP之下的任何JVM调用失败,例如:

  exec('java -version'); 

解决方法是在命令前加上

  export DYLD_LIBRARY_PATH =; 

另外我意识到没有理由使用这种调用mxmlc的方法。 b

所以下面是最后的工作命令:
$ b $ pre $ exec $'export DYLD_LIBRARY_PATH =; mxmlc MyAS3App.as -default-size 360​​ 280 -output MyAS3App.swf');


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.

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

Any ideas?

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

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

解决方案

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

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="";

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

So here's the final, working command:

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

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

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