Use SCRIPT_NAME not PATH_INFO in PHP

You should use

$_SERVER['SCRIPT_NAME']

not

$_SERVER['PATH_INFO']

in PHP. PATH_INFO has been monkeyed with in some versions (and when running as FastCGI?) so sometimes it appears as PATH_INFO and other times as ORIG_PATH_INFO and PATH_INFO does not exist in the $_SERVER array. SCRIPT_NAME seems to have had a far less chequered history. Sometimes I think there could be a new beautiful version of PHP without little gotchas like this, but then that wouldn’t really be PHP would it?

International Marketing Calls

“Hello, may I speak with the person there with responsibility for the telephone?”

Hang on, aren’t I registered with the wonderful Telephone Preference Service making any cold callers liable to a £20,000 fine? Yes, I am but this man does not sound English and this is a terribly odd sounding line if it is coming from inside the UK. Oh dear, I think I’ve just come face to face with a new phenomenon.

I guess voice-over-ip (internet telephone calls) means that it is now possible for companies not based in the UK to start cold calling into the UK. So now we need an international agreement on spam telephone calls?

All Possible Subsets

All possible subsets of a set is called a “powerset”. So, for the set { 1, 2, 3 } the powerset is:

{}, { 1 }, { 2 }, { 3 }, { 1, 2 }, { 1, 3 }, { 2, 3 } and { 1, 2, 3 }

One way to generate this set of sets is with the following recursive algorithm:

If S isn't empty: 
    pick the first element and call it "head" 
    call the rest of S "tail" 
    for each element e of the powerset of tail: 
        one element of the powerset of S is e 
        another is e plus head

Some code to generate this in PHP (apart from the empty set) is:

function powerset($stack, $set) {
    if (! $set) {
        return array();
    }
    $new_stack = $stack;
    $tail = $set;
    $head = array_shift($tail);
    $powerset_of_tail = powerset($new_stack, $tail);
    foreach ($powerset_of_tail as $e) {
        array_push($new_stack, $e);
        array_push($new_stack, array_merge($e, array($head)));
    }
    array_push($new_stack, array($head));
    return $new_stack;
}

We can add in the empty set and wrap the recursive code in a convenience function:

function get_powerset($set) {
    $powerset = powerset(array(), $set);
    array_push($powerset, array());
    return $powerset;
}

$set = array(1, 2, 3);
$powerset = get_powerset($set);

IBM’s Blue Gene/L, is the world’s fastest supercomputer. It is a 32-rack installation of the BlueGene system at the Livermore National Research Laboratory in California.

Blue Gene is a commercial product and buying even one rack automatically puts you in the Top 500 supercomputers list.

Blue Gene differs in approach from a number of previous “fastest ever computers” in that it uses low-power 700MHz processors rather than the latest-and-greatest chips coming off the production lines. This enables them to jam so much power into a small area and, more importantly, to be able to cool it.

Blue Gene/L covers just 2,500 square feet, uses just 1.5MW electricity which costs $100M dollars a year. These are low figures compared to previous fastest computers.

Blue Gene uses custom software based on Linux. The key is reliability. If a normal system has 1 failure per month then the Blue Gene/L would have a failure every 40 seconds. As Manesh Gupta (who worked on the software) says, “we ruled out Microsoft Windows”. This is achieved by using “system-on-a-chip design”, keeping the client access system separate from the main computational machine, using 1 of every 2 processors for network comms and keeping daemons and other “processor noise” producers to an absolute minimum.

To take full advantage of Blue Gene applications have to fully parallelised, use at least 32 processes (up to 64,000 for Blue Gene/L) and use no more than 511MB RAM per process. Programs can be compiled for the system from FORTRAN 95, C, C++ and MPI. The programs must also use static linking. GNU compilers have been ported.

Blue Gene/L has been used to produce a simulation of the behaviour of 2 million atoms. This took 48 hours, produced results that took a week to render in visualisation tools and will take the physicist involved a year to analyse and report on. The simulation was faster than the real world experiment would have been.

George Chiu and Manesh Gupta delivered a talk on Blue Gene at Imperial College today in a fairly hot lecture room where I put these notes together. Thanks guys.

SQL Server to MySQL

Just completed a fairly painless transition from SQL Server to MySQL. I used the very useful MSSQL2MySQL. No Triggers, Views or any other complicated stuff. In rewriting the SQL itself the only problems I had were with built in functions and the TOP command.

SQL Server to MySQL equivalent functions:

ISNULL => IFNULL (same syntax)
GETDATE => NOW (not CURDATE as that doesn't include the time)
SELECT TOP x => LIMIT x (at the end of the statement not after SELECT)
DATEADD => DATE_ADD

The Real Web on a Mobile

I have updated my actual-web-on-a-mobile program so that it copes with BBC Sport and various other sites better instead of giving an error.

The end result is that you have a text and links-only version of the web that will work on (some) mobile phones.

The program works by stripping all html except links and rewriting all links to point back at this server so those pages can be stripped once the links are clicked too.

You can search google and get the text of actual websites on your mobile without crashing your mobile’s browser or running out of memory here:

http://bluebones.net/miniweb/

You can enter a URL for stripping down to text and links only here:

http://bluebones.net/miniweb/?cmd=url

While you can use this service through your regular browser the reason this exists is for use with mobiles that understand HTML like the Nokia 7250i. You might be able to think of another use for these low bandwidth pages, please let me know if you do.

I’ve put up a snapshot of the source code but if you want the latest please contact me.

FileSystemObject Stops Working

Damn, just spent 30 minutes fixing a problem I first had in ASP over three years ago. The FileSystemObject just stops working and no error is reported. Just hangs forever. Then you need to do an iisreset or similar.

The problem is that Norton Anti-Virus’ “Script Blocking” doesn’t allow any use of the FileSystemObject. Even when it is set to “ask me what to do” when it encounters “scripting” it still just hangs. The simple fix is just to disable script blocking. Now I need to remember this for the next time.