This extension serves as a replacement for the class CAssetManager. It publishes content on the Amazon AWS S3, allowing you to enable and use a CloudFront CDN for your assets.
To install just unzip into the protected folder . Warning! I used as a basis the extension ES3, so if you have it installed you may have name conflicts.
Basic configuration:
'components' = array( ...... 'cache'=>array( 'class'=>'system.caching.CMemCache', 'servers'=>array( array('host'=>'localhost', 'port'=>11211), ), ), 's3' => array( 'class' => 'ext.s3.ES3', 'aKey'=>'ADD YOUR AKEY HERE', 'sKey'=>'ADD YOUR SKEY HERE', ), 'assetManager' => array( 'class' => 'S3AssetManager', 'host' => 'Your-bucket.s3.amazonaws.com', // changing this you can point to your CloudFront hostname 'bucket' => 'Your-bucket', 'path' => 'assets', //or any other folder you want ), ...... )
Done! Your assets will be stored on Amazon!
Total 10 comments
Hi, I've just modified your component to use MongoDB instead of memcached. Since memcached is volatile, if the locks are lost, content is uploaded again. MongoDB is persistent and very fast, so locks are safe there. If interested, I can send you the code (just send me a private message in the forum)
Andre,
I´ve created a cache component inspired on CDbCache but what it does is (for each request):
init : read the asset information from a database table and put it in memory
respond to Asset manager publish method with the corresponding information in memory
on Yii::app()->onEndRequest : update database table if needed
This component suites my needs for Amazon AWS deployment with autoscaling and no need to use ElastiCache
If you are interested I can send you the class I came with
Hello Andre,
I´m asking that because I´m planning to deploy on the cloud some day and it would be another component to manage ... Maybe in database or it will be slow also ?
GillesK,
Because you do not know if your asset is already published in S3 or not (and check that every request would be extremely slow), the solution I found was to store in the cache the items which were published.
Maybe there is a better way, but I could not think of anything.
Hello, Why do we need the memcached server ?
I get a include(S3.php): failed to open stream: No such file or directory
The S3.php file is inside extensions>S3
Am I missing something?
Could someone explain what the 'cache' section of the config is about? More precilse
What are those hostname and port?
For some reason Chrome requires the contentType to be 'text/css' to load properly, the asset manager uploads everything as 'text/plain'. Also, I kept having filename issue on uploading deep asset directories.
Here are my changes:
S3AssetManager.publish()
if (is_file($src))
AND
else if (is_dir($src))
Thank you Haykelbj!
Already correct and upload the extension.
I did not use the extension 'ES3' because it does not provide public access to all methods of S3 class (or at least I did not see how to access it).
Wow! I was about to implement this extension. Thanks!
I have just looked at the code on github and I noticed that the function S3AssetManager::getS3() is missing an if-statement:
missing line before 'throw':
One question: Is there a special reason why you did not use the 'es3' extension?
Thanks.
Leave a comment
Please login to leave your comment.