Question

I've been storing some simple user click-actions in text files so I can easily refer to them. I'm not looking to go the full db route, as I'm looking to learn hadoop, and should be able get the data from my log files, but until then I'm looking for a fairly light-weight solution.

I could continue with the txt file route, but it ends up being a lot of files (one for each type of user click).

What i was thinking of doing is putting an associative array into a text file (one for each day), and then reading in that associative array and updating key=>value to represent the click area and number of clicks.

Of course, I can't store an associative array directly in a txt file, without going through a bunch of 'read into an array', 'check array for existing key', 'update array', print out to txt'.

All of this just doesn't seem very efficient (even just reading the txt into the array is currently a bit of a pain).

I'm hoping somebody has a better suggestion for how I should do this.

Was it helpful?

Solution

Of course, I can't store an associative array directly in a txt file

Yes, you can. Just serialize the array before saving it.

OTHER TIPS

how are you storing them now? javascript?

have you considered google.com/analytics/

there are "serialize" functions available for php and javascript(3rd party) that will let you store arrays as text.

php.net/serialize

phpjs.org/functions/serialize:508

Two recommendations here to serialize the data, but when I was going through the 'serialize' stuff, I found a comment which says that storing json_encode is 'serialize() is always between 46% and 96% SLOWER than json_encode().' So i went the json encoded route. Pretty easy and fast.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top