Elliott C. Back: Internet & Technology

PHP Exclusive Single Process Mutex

Posted in Code by Elliott Back on May 31st, 2009.

When running php via cron, there are certainly situations where you only want a single instance of the php file to be running at the same time. Multiple processes shouldn’t be allowed. For example, every 5 minutes, a process is launched to poll for weather updates, and publish them to Twitter. If, for some reason, this process takes more than 15m–because Twitter is very slow–I don’t want more to buildup. At a rate of 12/hr, I would exhaust the number of MySQL connection on my box in a couple hours.

So, here’s the solution I used:

class pid {
    protected $filename;
    protected $fp;
    public $already_running = false;
    function __construct() {
        $this->filename = dirname(__FILE__).'/'.basename($_SERVER['PHP_SELF']) . '.pid';
        $this->fp = fopen( $this->filename, 'w+ );
        if ( !flock( $this->fp, LOCK_EX + LOCK_NB ) )
            echo "FAILED lock $this->filename\n";
            $this->already_running = true;
        } else {
            echo "Acquired lock $this->filename\n";
    public function __destruct() {
        if( !$this->already_running )
            echo "Releasing lock $this->filename\n";
            flock($this->fp, LOCK_UN);

It works fine from command line, but for some reason, doesn’t work when invoked via Apache over the web. But since I’m just using it for cron jobs, this is good enough for now. If you know why FLOCK( LOCK_EX + LOCK_NB ) won’t work when invoked through Apache, let me know!! I’m running PHP 5.2.6 (cli) and Apache/2.2.9 (Unix).

Last.FM, the RIAA, and TechCrunch

Posted in Computers & Technology,Copyright,Music,P2P by Elliott Back on May 24th, 2009.

TechCrunch refuses to let their claim that Last.FM gave CBS user data which was passed onto the RIAA lie. In a post called Deny This, Last FM, they claim that:

CBS requested user data from Last.fm, including user name and IP address. CBS wanted the data to comply with a RIAA request but told Last.fm the data was going to be used for “internal use only.” It was only after the data was sent to CBS that Last.fm discovered the real reason for the request. Last.fm staffers were outraged, say our sources, but the data had already been sent to the RIAA.

Reddit has noticed that TechCrunch is censoring comments critical of the post. Last.FM emphatically denies handing over the data:

Any suggestion that we were complicit in transferring user data to any third party is incorrect. […] It really seems like someone is trying to slander us here.

Here’s a more realistic, simpler explanation of what happened–one that wouldn’t require any special access to Last.FM’s private user data at all. The RIAA either asked CBS for the data, or got it themselves, from the public song timeline of Last.FM users. For example, at www.last.fm/user/elliottback/tracks you can download ~400 pages of songs I’ve listened to:


This gives them the following data: user, song, time. This is enough to tell that a user is listening to unreleased music, which is probably part of what the RIAA would use in trying to make a case against music pirates. For example–the Eminem Relapse album came out on May 15th, so theoretically anyone listening to it before then is a pirate.

T-Mobile Early Termination Fee Class Action Lawsuit

Posted in Cellphone,Deals & Savings,Law by Elliott Back on May 16th, 2009.

I just got a great postcard in the mail. This last year I was charged a $200 early termination fee by T-mobile, after Wendy had to cancel her plan and move back to Shanghai. Now, there’s a class-action lawsuit which is promising to refund $125 of the contract fee! Awesome!!

A proposed Settlement is pending in a class action entitled Milliron v. T-Mobile USA, Inc., No. 08-04149(JLL) (ES) in the U.S. District Court for the District of New Jersey. The lawsuit alleges that T-Mobile violated state and federal laws by charging customers a flat-rate early termination fee (“ETF”) in its wireless telephone service contracts. You are part of the lawsuit if you are a current or former T-Mobile wireless subscriber who paid or were charged a flat-rate ETF from July 23, 1999 to February 19, 2009, or if your contract for service included a flat-rate ETF from July 23, 1999 to February 19, 2009.

If you can prove you paid a flat-rate ETF, or T-Mobile’s records indicate you paid a flat-rate ETF, you may submit a Claim Form and receive up to $125.

You can go visit ETF-Settlement to read the details, and/or apply for a claim. I already did, as I received a postcard in the mail. However, if you meet the class-action criteria (pretty much anyone screwed by a T-mobile early termination fee), you should also fill out the form.

Next Page »