my life

day to day

Archive for July, 2007

PHP CoralCDN URL Transformer

Friday, July 27th, 2007

“CoralCDN is a decentralized, self-organizing, peer-to-peer web-content distribution network. CoralCDN leverages the aggregate bandwidth of volunteers running the software to absorb and dissipate most of the traffic for web sites using the system. In so doing, CoralCDN replicates content in proportion to the content’s popularity, regardless of the publisher’s resources—in effect democratizing content publication…”

http://coralcdn.org/

 Anyways, it’s free! So use it…



class CoralCDN
{
  
// const SUFFIX = '.nyud.net:8090';
  
const SUFFIX '.nyud.net';
  
// Returns a valid CoralCND URI
  
public static function getCdnUri($directUri)
  {
    
$parsed parse_url($directUri);
    
$uri = isset($parsed['scheme']) ? $parsed['scheme'].':'.((strtolower($parsed['scheme']) == 'mailto') ? null:'//'):null;
    
$uri .= isset($parsed['user']) ? $parsed['user'].($parsed['pass']? ':'.$parsed['pass']:null).'@':null;
    
$uri .= isset($parsed['host']) ? $parsed['host'] : null;
    
$uri .= isset($parsed['port']) ? '.'.$parsed['port'] : null;
    
$uri .= CoralCDN::SUFFIX;
    
$uri .= isset($parsed['path']) ? $parsed['path'] : null;
    
$uri .= isset($parsed['query']) ? '?'.$parsed['query'] : null;
    
$uri .= isset($parsed['fragment']) ? '#'.$parsed['fragment'] : null;
    return 
$uri;
  }
}
// Example Usage:
print CoralCDN::getCdnUri("http://user:pass@www.osterman.com:8080/foobar.html#123') . "n";

add to del.icio.us    add to technorati favs   email this