Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling java from PHP exec

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

like image 643
Keeth Avatar asked Nov 10 '08 19:11

Keeth


People also ask

Is Java a PHP?

PHP and Java are not the same as PHP is the server-side scripting language while Java is the general-purpose compiled programming language. PHP creates web applications and dynamics, while Java also powers dynamic web apps. Further, PHP comes as an open-source programming language with strong community support.


2 Answers

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');
like image 67
Keeth Avatar answered Sep 27 '22 02:09

Keeth


I manage to get this to work togheter with MAMP. The solution was to include the:

export DYLD_LIBRARY_PATH="";
in the exec call:

$argss = "export DYLD_LIBRARY_PATH=\"\"; /usr/bin/java -jar /Applications/yourjarfile.jar";
$resultXML = exec($argss, $output);
like image 20
Pontus Avatar answered Sep 27 '22 02:09

Pontus