tags:

views:

90

answers:

3

just yesterday i finished one site, which provides video watching. but now i need to show the number of views of each film. i never wrote such thing, so i don't know what to do.


maybe i must add one field in mysql database, and increase it every time the video opened? but i use flash player, and i can't wrote script onclick of player. so, could you give me an idea... thanks

+1  A: 

I'd create a table called video_views or something, have it contain the id of the video being viewed. I'd then use Flash's ExternalInterface functionality to call a JavaScript function which would, in turn, hit a remote URL via ajax to add a new record to video_views.

I've done this a few times in the past and it's always worked well. You could also just maintain a view_count value in your videos table and increment that each time a video is viewed.

[Edit]

One argument in favor of tracking each individual view would be the ability to add a timestamp to each record and gain further insight into things like peak traffic times.

inkedmn
@inkedmn coul'd you give some link about usage of ExternalInterface?
Syom
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/external/ExternalInterface.html
inkedmn
+1  A: 

The best way is probably going to be to just parse your webserver's log and look for when Flash requests the video stream (nightly cron job). I'm guessing you are using a pre-existing Flash video player, where you may not have the ability to modify the Flash to push a server request to update the view count when PLAY is clicked, nor do I recommend it because you might switch to another player or to HTML5 streaming.

As already suggest I also agree, just add a "view_count" to your "video" table and increment it, you can do it in one step with (no need to retrieve, add and update)

UPDATE video SET view_count = view_count + 1

Also keep in mind, if you incrimenting your video count upon loading the video page, make sure to exclude page views from search bots (ex: google) because half or more of your view counts could end up being search bots. You can find a list of search bot browser strings, so you know what to look for here.

TravisO
@TravisO i think i have to create a new table, with id_video and ip_user, otherwise one client can increase it many times.could you rewrite the part "make sure to exclude any search bots results by looking at the browser version tag", i don't understand what is that and why is that. thanks
Syom
Rewritten. and if you want a more reliable video count then using a dedicated table where you log each view is best, as you can exclude certain ones, repeat viewers, etc.
TravisO
A: 

Another way to go about it is to pass the web (Apache) Logs through a script real time by using the CustomLog directive as such

CustomLog |/var/www/view_count.php common

This would allow for real time statistics. Not sure if you need those or not.

Aaron