Calling java from PHP exec

15,292

Solution 1

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');

Solution 2

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);

Solution 3

Is there a reason why your using the mxmlc jar file to compile your flex application? have you tried using the executable or an ant task, instead?

Maybe the compiling is taking too long so that your PHP script times out?

Share:
15,292
Keeth
Author by

Keeth

Yay

Updated on June 04, 2022

Comments

  • Keeth
    Keeth almost 2 years

    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

  • Vladimir Dyuzhev
    Vladimir Dyuzhev over 15 years
    It's not a timeout. He's said it takes 2 seconds to compile it from the command-line.
  • Keeth
    Keeth over 15 years
    when I try compiling with ant i get the same result
  • Keeth
    Keeth over 15 years
    also when i try compiling with the mxmlc executable i get the same
  • ChenZhou
    ChenZhou over 14 years
    Wow, this saved my day! Thanks!
  • Erdal G.
    Erdal G. almost 10 years
    If you're still not getting any output, add 2>&1 in the end i.e. exec('java -version 2>&1');