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

#31
[eluser]tonydewan[/eluser]
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:

Code:
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.

#32
[eluser]MindFeed[/eluser]
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!

Thanks,
Bhargav Khatana

#33
[eluser]川红小霸王[/eluser]
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...

#34
[eluser]tonydewan[/eluser]
You'll need to be much more specific about the error and your environment before I can help.

#35
[eluser]川红小霸王[/eluser]
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
Code:
<?php $this->carabiner->css('basic.css'); ?>
can take place of
Code:
<link href="/assets/styles/basic.css" rel="stylesheet" type="text/css" />
?

#36
[eluser]川红小霸王[/eluser]
Im using your config file with default setting.Here is my root project structure.

|-assets
|--styles
|--scripts
|--cache
|-image
|-system
index.php

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

#37
[eluser]tonydewan[/eluser]
You still need to do this in your view:
Code:
$this->carabiner->display('css');

This goes in your controller, not your view.
Code:
$this->carabiner->css('basic.css');

#38
[eluser]川红小霸王[/eluser]
Thanks Tony, i will give it a try :-)

#39
[eluser]川红小霸王[/eluser]
i tried out this morning, it works perfect when i used two lines to load my css file
Code:
$this->carabiner->css('basic.css');
$this->carabiner->css('home.css');
but when i load them togerther using
Code:
$this->carabiner->css( array('basic.css', 'home.css') );
my cache file only showed me part of my css file.

#40
[eluser]Unknown[/eluser]
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:
Code:
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Title</title>
    <?php $this->carabiner->display('my_default_group'); ?>
    <?php $this->carabiner->display(); ?>
</head>

...

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
Code:
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.");
            return;
        
        endif;
    
    ...
Both of the if-statements will pass. That is bad.

change from:
Code:
if( empty($this->js) ) return; // if there aren't any js files, just stop!
to
Code:
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:
Code:
if( empty($this->css) ) return; // there aren't any css assets, so just stop!
to
Code:
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.