views:

131

answers:

3

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.

A: 

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

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

dutch
+1  A: 

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

dogatonic
thanks for the 'serialize' stuff, that is the right answer. So you get a point! I gave Dutch the win 'cause he got right to the point, but now I'm wishing I could have rewarded you for your thoroughness, sorry about that. I am using analytics, buti'm looking for data on where the user clicked, not what page they went to. Could be me, but I don't see the click location data in analytics. I am passing the location via ajax to a php page, because the click has usually leads to an ajax response.I try not to give too much info and confuse people, but maybe I didn't give enough this time.
pedalpete
A: 

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.

pedalpete