Calling java from PHP exec

前端 未结 4 941
陌清茗
陌清茗 2020-12-01 15:17

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 M         


        
相关标签:
4条回答
  • 2020-12-01 15:44

    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');
    
    0 讨论(0)
  • 2020-12-01 15:52

    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?

    0 讨论(0)
  • 2020-12-01 15:57

    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);
    
    0 讨论(0)
  • 2020-12-01 16:02

    Exec is always tricky, on any language :-)

    Try to:

    • use background execution (add & symbol at the end)
    • use shell_exec instead
    • specify the full path to java executable (may be the one available to PHP is not the one you need?)
    • run a simple HelloWorld java app to see if the problem is in Java or in mxmlc specifically

    It's strange that java takes 100% CPU. I cannot explain it with any common mistake made when using exec()... try to send it a SIGQUIT to dump the threads, then read the dump -- may be you'll figure something out.

    0 讨论(0)
提交回复
热议问题