Viewed   74 times

I am doing the following in PHP:

exec('java -jar "/opt/flex3/lib/mxmlc.jar" +flexlib "/opt/flex3/frameworks" -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 (

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

exec('java -version');

The fix is to prefix the command with


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 -default-size 360 280 -output MyAS3App.swf');
Thursday, September 22, 2022

Actually you can push data from the server to the client, when using Flash sockets (which means bypassing the http protocol). If you cannot use sockets you can use things like polling, long polling or http streaming. However it will take a while to do everything by hand, so I suggest looking at a product which already has this features. WebOrb for PHP is one of them, and from what I know is free.

Tuesday, November 29, 2022

Does your computer have UAC turned off? (Windows 7 or Vista, accessing C: with out UAC perms will error so for ease turn it off),

Secondly, exec requires a string input,

Thirdly need to be escaped as Phill said

exec('java -jar "C:/batik/batik-rasterizer.jar" -m C:/pathto/image/png -d 
"C:/pathtoimg/temp/2fa8af078803491746235057c546c1b6.png" -w 800 


Check that your allowed to use exec/system/backticks, using the CLI

  1. Create a php file with <?php exec("echo hello"); ?> inside it save it
  2. Then start CMD,
  3. open a new window (open up my/ computer) and browse to your php.exe application
  4. copy the address of the folder where you found it
  5. in cmd type "cd " without quotes and after that right click and click pase then hit enter
  6. type "php " (again without quotes) drag php file saved to the cmd box and drop it
  7. then hit enter and see if it says hello in the cmd box

if this does not work check java is working without path to exe, in the cmd windows type your java --help and see if it works

Tuesday, August 2, 2022

In re-reviewing the code, I noticed that I shouldn't have escaped the single-quotes. They're valid for the actual execution and I should only escape DOUBLE quotes for php in this instance...

The final code looks like this (for future reference) :

$name = "generated";
$phone = "";
$url = "";

if(isset($_POST['name'])) {
    $name = $_POST['name'];
if(isset($_POST['phone'])) {
    $phone = $_POST['phone'];
if(isset($_POST['url'])) {
    $url = $_POST['url'];

$swfname = $name . ".swf";

$generate_command1 = "export _JAVA_OPTIONS="-Xms32m -Xmx64m"; /opt/flex/bin/mxmlc -define+=NAMES::Name,"'$name'" -define+=NAMES::Phone,"'$phone'" -define+=NAMES::Website,"'$url'" -output /path/to/my/webserver/httpdocs/swfbuilder/$swfname";

exec($generate_command1, $out);
Saturday, September 17, 2022

Typically this is a path problem. The application you're trying to call is probably not in the search path of the web server's user account. I only call applications from PHP using the full path. I store that path in settings files so it works across any system it's used on.

Tuesday, November 8, 2022
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :