Following on from above suggestions you could have a look at the DB_BTREE format of
DB_File. This stores keys in a given order so you could use timestamps as your keys and a
$b <=> $a compare function, and be able to retrieve values in a last in first out style. Much easier to implement than a database.