/    Sign up×
Community /Pin to ProfileBookmark

Efficient way to log page impressions?

I’ve been working on my affiliate program for my software, and I’ve finally finished it, now I’m working on the dashboard.

I decided that I wanted to add impression statistics to the dashboard (Amount of page views).

The way I thought about doing this was saving a row into a database every-time the page was loaded, with a key-value of the affiliates user-name, and then the date.

This would definitely work, and do what I want it to, however this would populate the databases ridiculously quickly.

I will have to store the impression data for three months, and if a single affiliate is generating 1,000 impressions per day, that’s 1,000 rows in the database, seems highly inefficient.

What do you guys recommend as an efficient way to do this?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 04.2014 — Firstly, don't underestimate the efficiency of a properly designed and indexed database. I work on a project with one DB table that has over 80,000,000 rows, and it gets joined on by all the most common requests to that system. Granted, you're looking more at inserts than selects, but that should not be a major difference versus writing to a file.

That being said, is the info you need already available in the HTTP logs (and do you have access to them)? If so, maybe some sort of cron job that periodically (nightly?) parses them for the data of interest and updates a database (or text file?) with the counts of interest could serve your purposes. (Could be a good time to learn Awk.)
Copy linkTweet thisAlerts:
@CTucker1327authorNov 05.2014 — Firstly, don't underestimate the efficiency of a properly designed and indexed database. I work on a project with one DB table that has over 80,000,000 rows, and it gets joined on by all the most common requests to that system. Granted, you're looking more at inserts than selects, but that should not be a major difference versus writing to a file.

That being said, is the info you need already available in the HTTP logs (and do you have access to them)? If so, maybe some sort of cron job that periodically (nightly?) parses them for the data of interest and updates a database (or text file?) with the counts of interest could serve your purposes. (Could be a good time to learn Awk.)[/QUOTE]


The logs can generate impressions based on the ___FILE___ base name, however I need to save the impressions based on a parameter.

http://example.com?ref=352

would log a click under referral 352, and so forth.

I'll design a database for this, I think I found a decent way to handle it.
Copy linkTweet thisAlerts:
@NogDogNov 05.2014 — As long as it's in the URL (i.e. a GET request), it would part of the HTTP logs, should that route interest you; but if you can control it directly from the application, that's probably more robust and flexible. (Hey, if you get so much traffic that it becomes an issue, then buying additional servers should be a minor issue. ? )

Just a thought, you could put the logging stuff into a separate PHP file, and have it called before any PHP page runs via the [url=http://php.net/manual/en/ini.core.php#ini.auto-prepend-file]auto_prepend_file[/url] configuration directive, then you wouldn't even have to bother adding include/require statements to your existing scripts.
×

Success!

Help @CTucker1327 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.4,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...