Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to hash the js file using asset management


I work with Ruby on Rails and on my dev machine my css files might be named application.css and ui.css or whatever but when rails deploys it will compile all those files into one file with a name like:


How can we do it in phalcon? I would like to hash the filename.

advice appreciated.

the minification you can do it with the asset manager. A plain file name should be fine, but if you really want hashing, md5 should be enough for this purpose.

It works for both css and js:


Hi there,

Thanks for reply. I am already using asset manager. Noticed we have to set the filename. How do we md5 it?

// The name of the final output

// The script tag is generated with this URI
edited Jul '15

the md5 utility is somewhere on the OS, so you'll need to know if your server has md5sum or md5 and where to get it, then in PHP use exec(). I have Windows 8.1 on my other PC, but kind of lazy to go check if it has MD5, I think it doesn't, I think its a 3rd party thing on Windows.

On Macs md5 is reachable anywhere so there is no need for the full path to it, your server may need the full path, you'll need a bit of trial and error to find out. Try a few probes in PHP:

echo exec('whereis md5'); // or md5sum, or just try ...
echo exec('md5 path/to/somefile.css');

Actual anwser to your question is:

$checksum = exec('md5 -q /Users/edward/Desktop/example.css');
// -q is quite mode, only the checksum is returned, without it, you'll get:
// MD5 (/Users/edward/Desktop/example.css) = 5e7f4d0bfa9da0c1527086c373dfc15f
// ... ain't got time for dat!
// btw that flag stuff is described in the man pages
// man md5

edited Jul '15

@Derek md5 is part of php. You don't need any exec.

->setTargetPath(md5("final") . ".js")

@Edward don't forget that phalcon is a php framework. No point in overcomplicating things when php already provide you the needs of hashing


Thank you guys!

@stefan Oh right, there is md5_file() and sha1_file(), and more, that's new to me, thanks. Normally I don't do it this way, I'll just append a time stamp so the CSS or JS isn't cached.