• PHP House of Horrors

    13 Nov 2006, 17:45 by Russ

    Two weeks late for hallowe'en, but here's my latest PHP nightmare. Consider the following two pieces of PHP4 code, from a singleton pattern (apologies for the formatting, I need to fix our BBCode):


    function &instance() {
    global $httpmanager_instance;
    if (!isset($httpmanager_instance)) {
    $httpmanager_instance =& new HTTPManager();
    return $httpmanager_instance;


    function &instance() {
    if (!isset($GLOBALS['httpmanager_instance'])) {
    $GLOBALS['httpmanager_instance'] =& new HTTPManager();
    return $GLOBALS['httpmanager_instance'];

    They're identical right? Wrong. "global $var" doesn't act the same as "$GLOBALS['var']".

    In fact, "global $var" is equivalent to "$var =& $GLOBALS['var']", which means that example A above is equivalent to:


    function &instance() {
    $httpmanager_instance =& $GLOBALS['httpmanager_instance'];
    if (!isset($httpmanager_instance)) {
    $httpmanager_instance =& new HTTPManager();
    return $httpmanager_instance;

    Now it should be (more) obvious what is happening. $httpmanager_instance contains a reference, which is getting replaced when you use =& on it, while the actual global variable remains empty. The answer in this case is to use = instead of =&, because in that case, PHP will follow the reference and replace the original variable:


    function &instance() {
    global $httpmanager_instance;
    if (!isset($httpmanager_instance)) {
    $httpmanager_instance = new HTTPManager();
    return $httpmanager_instance;

    This is equivalent to B above.

    Now I'm not entirely sure what the PHP developers were thinking when they decided to make references and variables appear identical, but they certainly weren't following the Rule of Least Surprise...

    But PHP5 fixes all this, right?
  • Site update, and what is coming next

    31 Oct 2006, 14:33 by RJ

    Finally, we got the site update out.. Flash was causing us some last minute headaches and late nights. We still have some tweaking to do serverside but we are well on the way now. It is great to be able to listen when not at your computer, without the client.

    Events are flooding in, i'm looking forward to going to an event i discover via lastfm and meeting other lastfm'ers there :)

    The similar artists algorithm was changed for this update too - so similar artist lists on artist pages may be slightly different. I'd appreciate any feedback on that. (Use the google cache to check the old data if you want to compare)

    Aside from the similar artist stuff, norman has cooked up some better data for the tastometer, including ways to slice and dice your profile against another and see what you have in common /different.

    We'll be doing housekeeping and pushing out fixes/tweaks all week. Bug reports/feedback in the usual place please :)
  • Screenshots of new beta site

    24 Oct 2006, 21:40 by RJ

    Subscribers are currently helping test-drive the next lastfm website update.

    Here are a couple of screenshots of the new artist page design:

    Artist page 1
    Artist page 2
  • New website beta for subscribers is online

    20 Oct 2006, 18:15 by RJ

    The October beta (subscriber only beta) is online:

    Check it out and leave some feedback in the group forum :)
  • New Audioscrobbler Protocol

    3 Oct 2006, 14:01 by Russ

    The first draft of the long-overdue Audioscrobbler Protocol 1.2 is out. Read more here (comments in that thread, please).
  • Scrobbling Visualisations

    13 Sep 2006, 23:02 by Russ

    I've been working on geographic visualisations in my spare time. Here's an animation of the number of scrobbles over a 24-hour period:


    (click for the animation, 4MB animated GIF)
  • Worst PHP "non-bug" of the day

    18 Aug 2006, 16:14 by RJ

    Guess the output:

    class Foo {
    function blah(){
    echo get_class($this);
    // ...

    class Bar {
    function doFoo(){
    return Foo::blah();

    $bar = new Bar();

    What's that I hear you say? $this will be undefined in blah() because the method is called statically?

    Think again. The "$this" within the blah() method is actually a reference to the instance of Bar that is calling it.

    If anyone cares to enlighten me as to the logical gymnastics required to possibly come to terms with this, I would be extremely interested. Words cannot express my dismay and disgust at how this is implemented.

    From the PHP manual:

    Note: The $this pseudo-variable is not usually defined if the method in which it is hosted is called statically. This is not, however, a strict rule: $this is defined if a method is called statically from within another object. In this case, the value of $this is that of the calling object.
  • Updates to Audioscrobbler submission process

    9 Aug 2006, 16:26 by RJ

    In future releases of the software we will be blurring the line between streaming from and listening to local content. I'll write more about this later, but it has caused us to examine how the submission process works.

    Currently it works like this:

    - When listening to the radio, songs are scrobbled at the end of the song, or when you press skip or ban.

    - When listening locally (iTunes, winamp etc.), songs are scrobbled after 240 seconds or 50% of the song has been played, whichever comes first. Songs less than 30 seconds in duration are ignored. It is possible to skip a song after the 50% threshold, which means it has already been scrobbled.

    We want to unify this so that all songs are treated equally, regardless of the source. It's quite confusing at the moment that local playback scrobbles half way thru and radio playback at the end.

    Here's what we have in mind. I'm posting it here to get some initial feedback before any development takes place. It's quite a subtle change:

    - All songs will now be scrobbled (aka, submitted / sent to server) when the track has finished. Either when it has played all the way thru, or when it is skipped/banned.

    - There will be an (advanced) option in the client where you can set a slider from 50% to 100%. This dictates when the song is considered played enough to scrobble. For example, if you set the slider to 50%, the song is marked as scrobbled when you've listened to 50% of it. If you then press skip 10 seconds from the end, it will still be scrobbled. If you set the slider to 100%, you need to listen to the entire song for it to be scrobbled.

    So if we make the default setting of the slider 50% it will appear to have the same behaviour as the current plugins.
    The difference being that the actual submission is deferred to the end of the song, which allows us to factor in any last minute ratings, and ultimately give more control to the client software to decide how and when scrobbling takes place.

    The only obvious change to most users is that your "10 recent tracks list" would then not update until after the song has finished. Currently it adds the current song half way thru. (or 240 secs, whichever comes first).

    To address this, we will add an addional step to the submission process. Plugins will be able to ping the server as soon as a new track starts playing. This will act as a realtime "now playing" indicator. A new one-liner will appear just above the recent tracks list which indicates "now playing". If the song you are now-playing is actually submitted, it will appear in your recent tracks list as normal, and disappear from the now-playing indicator.

    This update will give us realtime now-playing information for the website (and chart images/webservices), and also push more responsibility of when/how to scrobble onto the client, giving the user more control.
  • Audioscrobbler Pics from 2002

    26 Jun 2006, 10:48 by RJ

    I was browsing the old stuff on our static image server and found these screenshots from 2002:

    Inflated scrobbling using multiple instances (doh)

    Stupid error messages

    Yeah.. the original winamp plugin kinda sucked :)
    The first pic is one of the few pictures of what the original website looked like too.. that was hosted at Southampton uni in 2002. I remember getting slashdotted and the network admin inviting me to his office for a chat :)

    See my previous post if you want to try the new audioscrobbler beta.
  • The New Audioscrobbler Software

    23 Jun 2006, 23:15 by RJ

    As mentioned elsewhere in various threads - a beta version of the new audioscrobbler is available, currently supporting winamp, windows media player and itunes on windows. Other platforms and players will be supported soon.

    Here is a screenshot of the development version running on Linux/KDE:

    Download the windows beta installer here.