Instant Storage

Here’s one of my favorite PHP ‘hacks’: when I’m whipping up a quick script that needs a place to stash some persistent data, but don’t feel like coming up with a database structure, or doing anything remotely approaching a real solution, I instead stuff it into a “static” session. By static, I just mean that I set the session ID to a static value, so I’m always pulling the same session. Instant data store.

$_SESSION['stuff'] = $w00tz;

(Another quick and dirty approach would be serializing an array into a local file… oh, wait, I just recreated the default PHP session handler. ;))

1 Comment so far

  1. andrew on February 24th, 2009

    It’s also worth noting that this isn’t limited just to scripts accessed via the web — while sessions typically use a cookie to transport their ID, we’re hard-coding our ID, so we don’t need cookies (or HTTP, for that matter): this works just as well in a CLI script.

Leave a Reply