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";
Posted in uncategorized | No Comments »
June 30th, 2007
We’ve just released our MogileFS Client for PHP (5.1). It does a very good job of handling errors and is being used in production on Socialverse.
You might also want to consider this PECL module that implements the protocol. Personally, I don’t see many performance advantages to using this module. The native PHP MogileFS class above uses CURL for almost everything, which is an efficient library for HTTP communication all in C. CURL also comes standard with almost every PHP packing system that I’ve seen, so you don’t need to maintain yet another PECL.
Posted in coding | 4 Comments »
June 27th, 2007
I am constantly sending links to my friends. Problem is, I don’t know if my friends appreciated the link or hated it. Also, it’d be neat to see if they liked it so much they passed it on to other people. On the receiving end, I like getting links from my friends because they know what I like and we have many things in common. It’s a sort of natural filtering process where the crap dies and the good stuff lingers on. If this sounds like something you run into on a daily basis, you should check out http://psstit.com/. What’s especially cool is that you can get an RSS feed of links your friends send you. That way, you can check them out at leisure.
Posted in uncategorized | No Comments »
June 26th, 2007
Trying to deploy something today and ran into the error
`initialize’: No such file or directory - /tmp/ssh-IOIwF31501/agent.31501 (Errno::ENOENT)
Turns out it’s related to the passwordless ssh login.
Running the following fixed these issues:
$ ssh-agent bash
$ ssh-add
Posted in uncategorized | No Comments »
June 13th, 2007
function eeval($string)
{
$result = @eval($string);
if( isset($php_errormsg) )
throw new Exception($php_errormsg);
return $result;
}
Posted in coding, notes | No Comments »
June 13th, 2007
In the process of writing a MogileFS client in PHP, I discovered there’s no no straight forward way to issue a PUT request using CURL where the body of the request comes from a string, rather than a file. Luckily, PHP 5.2 introduces memory based streams…
$fh = fopen('php://memory', 'rw');
fwrite($fh, $dataToPut);
rewind($fh);
$ch = curl_init();
curl_setopt($ch, CURLOPT_INFILE, $fh);
curl_setopt($ch, CURLOPT_INFILESIZE, $length);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_PUT, 4);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array('Expect: '));
$response = curl_exec($ch);
fclose($fh);
Posted in coding | 9 Comments »
June 13th, 2007
PHP offers a way to parse a stream handle, but not way to parse just a string. Here’s a simple/lazy way to parse a single CSV line in PHP:
function parseCSV($str, $delimiter = ',', $enclosure = '"',
$len = 4096)
{
$fh = fopen('php://memory', 'rw');
fwrite($fh, $str);
rewind($fh);
$result = fgetcsv( $fh, $len, $delimiter, $enclosure );
fclose($fh);
return $result;
}
Posted in uncategorized | No Comments »