storing a hashmap permanently
Moderator: General Moderators
- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
storing a hashmap permanently
hello, i am looking to store something like an hashmap(set of key:value pairs) but i do not really want to save it in mysql db. i want to keep this as close as possible to php code in file system. it needs to be stored permanently so that it can be retrieved in subsequent requests. the value wont be big but the hashmap set may grow. there is a very good chance of too many retrievals and deletions happening on it. so, what is the best way to do it; i do not really want to do manual file related operations (retrieving, finding, deleting, saving, etc) as they would be slow. any readymade solutions available? or should i use sqlite?
Thanks for your suggestions.
EDIT: is there is anything available from zend framework???
Thanks for your suggestions.
EDIT: is there is anything available from zend framework???
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
This sounds like a job for..... MySQL! Seriously, that's pretty much a clear-cut case of when to use a DB. Performance wise it's way more expensive to do just about anything else. DB engines are optimized to all hell.
If you're looking to keep the app portable, have you considered SQLite?
If you're looking to avoid a bunch of SQL, you could always whip up a simple DAO for your hash (and have it handle the SQL).
Or you could do both and be too cool for school.
If you're looking to keep the app portable, have you considered SQLite?
If you're looking to avoid a bunch of SQL, you could always whip up a simple DAO for your hash (and have it handle the SQL).
Or you could do both and be too cool for school.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
To all intent and purpose, arrays are equivalent to HashMaps in Java. You can serialize an array easily enough:
And to get it back:
I could work with that... K.I.S.S 
Code: Select all
$data = array();
$data["key1"] = "value1";
$data["key2"] = "value2";
file_put_contents("data.sore", serialize($data));Code: Select all
$data = unserialize(file_get_contents("data.store"));- raghavan20
- DevNet Resident
- Posts: 1451
- Joined: Sat Jun 11, 2005 6:57 am
- Location: London, UK
- Contact:
i hope this would be as fast as i do expect. thanks both of you guys.d11wtq wrote:To all intent and purpose, arrays are equivalent to HashMaps in Java. You can serialize an array easily enough:
And to get it back:Code: Select all
$data = array(); $data["key1"] = "value1"; $data["key2"] = "value2"; file_put_contents("data.sore", serialize($data));
I could work with that... K.I.S.SCode: Select all
$data = unserialize(file_get_contents("data.store"));
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
I know the php manual user comments used to be stored in a separate set of files as base64-encoded strings in an "ini file" structure. Not that I advocate this method, but it served them well for years.
You could also store the hash as a serialized object, though I guess an array would be simpler in that case.
You could also store the hash as a serialized object, though I guess an array would be simpler in that case.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia