by

Laravel Asset Compressor Bundle and filemtime() stat error

This appears to only be a problem with Windows. If you see an error like this while using the asset compressor:

filemtime() [function.filemtime]: stat failed for [some file path]
Location:
 
E:\www\yourapplication\laravel\file.php on line 136

know that the code probably works on Linux and OS X, but not on your own Windows machine.

Why?

OS X and Linux use / as a directory separator. Windows uses \. PHP is tolerant of this, but the Google Closure Compiler that does the heavy lifting for this bundle is not. It doesn’t work with Windows paths containing \, like the ones the Asset Compressor has generated for it to use. If you get the command that the asset compressor generates (look for exec("$java $jar $scripts_to_minify $out_script");), replace all the \ with /, and run that line through the command line, you may find it works!

The Quick Solution

Set the enabled property in the bundle’s config file to something like this to disable the compressor on Windows, and enable it on other operating systems with the right directory separator:

    'enabled' => DIRECTORY_SEPARATOR == '/',

If your live server uses Linux, the compiler will compress your assets the first time someone visits your site. This can add several additional seconds to any page load that triggers the compiler.

The Smarter Solution

Fork it, fix it, pull request it.