topical media & game development
mashup-delicious-11-delcache-create-s3-cache.php / php
<?php
//existing bucket name
define('BUCKET_NAME','username_delcache');
//access and secret keys for your s3 account
define('S3_ACCESS_KEY','accesskey');
define('S3_SECRET_KEY','secretkey');
// pear installed goodness
require_once 'Crypt/HMAC.php';
require_once 'HTTP/Request.php';
//other s3 settings
define('S3_URL',"http://s3.amazonaws.com/");
define('ACL_SETTING','public-read');
//the date and time in rfc 822
rss = fetch_rss(MY_FEED_URL);
//create and/or update the cache for each item
foreach (item) {
item['link']);
//get the contents of the file you want to cache
item['link']);
response_code = file_content_type = file_contents = file_contents != '')
{
//assemble your s3 signature
content_type."\n".file_key;
signature = hex2b64(s3_signature));
//make the request to create the file in the bucket
file_key);
s3req->addHeader("content-type", s3req->addHeader("Date", s3req->addHeader("x-amz-acl", ACL_SETTING);
signature);
file_contents);
s3req->getResponseCode() == 200) {
echo "Cache updated for ".file_key.")\n";
} else {
echo "Problem updating cache for ".file_key.") - Status was ".item['link']." (".req->getResponseCode()."\n";
}
}
function hex2b64(raw = '';
for (i < strlen(i+=2) {
str, raw);
}
?>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.