my life

day to day

Archive for June, 2007

Robust PHP MogileFS Client

Saturday, 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.

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

Psst it on!

Wednesday, 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.

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

Cap Oddity `initialize’: No such file or directory (Errno::ENOENT)

Tuesday, 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

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

PHP Exception Throwing Eval

Wednesday, June 13th, 2007



  
function eeval($string)
  {
    $result = @eval($string);
    if( isset($php_errormsg) )
      throw new Exception($php_errormsg);
    return $result;
  }

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

PHP CURL PUT String

Wednesday, 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($chCURLOPT_INFILE$fh);
    curl_setopt($chCURLOPT_INFILESIZE$length);
    curl_setopt($chCURLOPT_TIMEOUT10);
    curl_setopt($chCURLOPT_PUT4);
    curl_setopt($chCURLOPT_URL$url);
    curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
    curl_setopt($chCURLOPT_HTTPHEADER, Array('Expect: '));
    $response curl_exec($ch);
    fclose($fh);

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

PHP CSV Parsing

Wednesday, 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;
}

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

Los Angeles Time Lapse

Monday, June 11th, 2007

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