We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon\Assets\Manager YUI Compressor does not work on Windows

Title may be a misleading, this isn't directly Phalcon issue it appears, running the examples as shown here won't work on Windows 8, below is a simplified direct test, it just won't produce any output. If I try the command directly in the command line, I do get the compressed CSS file output.

$result = shell_exec('java -jar d:/yuicompressor-2.4.8.jar --type css --charset utf-8 main.css -o main-min.css'); // $result is empty

I've tried system() as documentation example shows, and exec() as well.

Is there some setting within Windows, Java exe or PHP that will allow this to happen, or is using PHP to execute a .jar file a dead end on Windows 8?

Thanks.

What is the output if you run the same command in CMD?

Hi, thanks for your reply. Only the minified file will be produced, the YUI .jar file does not provide status result when run in CMD. exec("java -version"), or when full path to Java, return nothing as well, exec("dir") does return the directory files for examle.

I've given up this approach, just using a custom asset filter as a file joiner, I'll minify them with YUI manually, there are PHP based minifiers but not as simple as YUI compressor, only one .jar file, one command. I cannot use Phalcon minifiers because of the "non-free" error on Windows.



5.7k
Accepted
answer
edited Oct '15

Edit: Months later after installing Java 1.8, and Windows 10, this no longer works, I don't know if its a security thing on Windows or PHP, but nothing happens. I tried calling nodejs modules, they won't respond either via exec, nodejs itself will respond but not a module.

Ok I got it working now!

// On my machine, only full path to Java.exe worked.
echo shell_exec('CALL "C:\Program Files\Java\jre7\bin\java.exe" -jar d:/yuicompressor-2.4.8.jar --type css --charset utf-8 main.css -o main-min.css');

CALL made it work.

I was trying to find out if I could run Java via a Windows batch file, same thing, using CALL worked from PHP, CALL is not needed if running the batch file directly in CMD. Here is the bat file, if anyone is interested.

@echo off

IF "%1"=="" (
    ECHO 'No arguments! 3 required. 1-type-js/css 2-input-file 3-compressed-file'
) ELSE (
    CALL "C:\Program Files\Java\jre7\bin\java.exe" -jar d:/yuicompressor-2.4.8.jar --type %1 --charset utf-8 %2 -o %3
)

Called like this:

run_yui_compressor.bat css main.css main-min.css