• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Carabiner 1.0: Asset Management Library

I don't know nearly enough about load balancing work to provide anything but pointers. The filenames that Carabiner creates are a concatenation between the last-modified-time (filemtime in PHP) of the most recently modified file, and an MD5 hash of all of the asset filenames (in the group) put together. I'm assuming, then, that the part of the filename that is different is the filemtime string, though I'm not necessarily sure why it would be different (unless your losing resource info when moving to the load balancing servers; at that point, filemtime would probably show as when the file was moved to the server.) If that is indeed the problem, a simple (but not necessarily scalable) solution (assuming you're on Unix) would be to run this command on whatever the most recently modified file is:

touch -mt 0711171533 /PATH/TO/ASSETFILENAME.js

where 0711171533 is a Unix timestamp.

Otherwise, you'll need to come up with a better way to create unique filenames, or store the filenames in a database. In the case of the former, let me know if you come up with something. In the case of the latter, I would store the MD5 hash as your key, and then when a new file is created, store that filemtime. Then, every time a file is to be created, check for the hash, and if the filemtime is less than an hour (or whatever) older than the one you have, use the one from the DB. Of course, that puts more load on the databse, which in the long run is not the best plan.

If I come up with something better, I'll let you know.

Thanks for your thoughts into the problem. Though if I keep the file name same, the problem stands as it is. As each and every request has been distributed among 5 apache servers through load balancer, if LB hit the first server for getting the PHP->HTML page, it might hit any of 5 server for loading various resources like images, css, javascript. So in this case only first server has the combined/minified javascript/css files and not other servers and hence response will be 404 with the rest of 4 servers, unless and until LB hit that server for PHP->HTML page.

Just preliminary thoughts towards solution:

=> Lets store the combined/minified version to DB, centrally accessible to all the servers.
=> Table will have four fields, asset_key, asset_type, asset_content, asset_dt
=> Store filename in asset_key (without extension, jst lastmodified + md5(filenames)), 'js' or 'css' in asset_type, combined and minified version to asset_content, and timestamp to asset_dt
=> In library we will check filename against asset_key in database instead of checking file on hard drive.
=> Modify _cache function to write into database instead of writing on disk
=> Modify _tag function where instead of including the combined/minified version of javascript/css from cache directory, will include path to controller/function which in turn read the database and echo the content with proper heading.
=> In that controller/function, I also can set proper caching header, after checking ETag and IF-Modified-Since

howz that!

Bhargav Khatana

i hava a problem using this library, after set it up, when i run my proejct,it showed me an error "Message: Invalid argument supplied for foreach()", how to fix the error?thanks...

You'll need to be much more specific about the error and your environment before I can help.

Thanks for reply,Tony.

Actually the error is no longer existing, but my css file still dosent work, and im quite sure my setting is correct. So i just wonder when i add a css file into my view, is that mean
<?php $this->carabiner->css('basic.css'); ?>
can take place of
<link href="/assets/styles/basic.css" rel="stylesheet" type="text/css" />

Im using your config file with default setting.Here is my root project structure.


I put all my css files into styles folder and all js files into scripts.

You still need to do this in your view:

This goes in your controller, not your view.

Thanks Tony, i will give it a try :-)

i tried out this morning, it works perfect when i used two lines to load my css file
but when i load them togerther using
$this->carabiner->css( array('basic.css', 'home.css') );
my cache file only showed me part of my css file.

Hello! Great system thank you! Smile
I am using version 1.45. Here is a solution to a bug.

The bug:
In one of my views i have the following code:
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <?php $this->carabiner->display('my_default_group'); ?>
    <?php $this->carabiner->display(); ?>


Some times I add assets to the main group but sometimes I do not.
When I do not the system fails and outputs a non-existing file in the header.

The Solution:
Take a look at this code segment from a non modified version 1.45
private function _display_js($group = 'main')
        if( empty($this->js) ) return; // if there aren't any js files, just stop!
        if( !isset($this->js[$group]) ): // the group you asked for doesn't exist. This should never happen, but better to be safe than sorry.

            log_message('error', "Carabiner: The JavaScript asset group named '{$group}' does not exist.");
Both of the if-statements will pass. That is bad.

change from:
if( empty($this->js) ) return; // if there aren't any js files, just stop!
if( isset($this->js[$group]) && empty($this->js[$group]) ) return; // if there aren't any js files, just stop!

The same goes for the css function:

change from:
if( empty($this->css) ) return; // there aren't any css assets, so just stop!
if( isset($this->css[$group]) && empty($this->css[$group]) ) return; // there aren't any css assets, so just stop!

By the way: I would like to help you improve this library more directly. Is this in a repository somewhere I could get access to?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.