advetising script help

Discussion in 'PHP' started by jasondavis, Feb 12, 2008.

  1. #1
    Hi guys I am working on building a custom adertising script for my site, my site is pretty high traffic so performance is always number 1 priority


    Advertisements
    - Can be html/flash/text anything
    - Have to update impressions and stats on every load
    - Will randomly show between all ads in the DB that are active
    - I can even ad my adrite ads or google adsense code into an ad campaign.
    - expire banners after x amount of time
    - add weight to banners to show more often
    - enable and disable banner option.

    Admin
    - Add/edit/remove ads
    - Can see impressions/click stats for any ads


    User - person paying for advertising on my site
    - Will get to see a page with an ID number used as $_GET to view stats on there ads, including start date, end date, clicks, impressions


    Question 1)
    I question here is what is the best way to update impression count when an ad is shown, it would seem that selecting random ad from DB and then Updating impression count on every page load is not the best performance, is there better ways to do it?

    Question 2)
    I know how to show a random ad, but if ads have a weight system of 1-10 or 1-5 how can I go about making higher numbers show more often?

    Question 3) For keeping track of clicks and impressions per day what is the best way to do this, maybe make a new row in DB every single day for every single ad in DB and then update that row everyday?
     
    jasondavis, Feb 12, 2008 IP
  2. Cobnut

    Cobnut Peon

    Messages:
    184
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi Jason,

    1) If you want to keep accurate stats then I really can't see any option other than to record each impression and that means updating the db on each page load. The code for doing this can be very small indeed and should be very rapid - let's face it, there's far more complex stuff going on in most db backed pages and they'll load in a flash so a simple UPDATE ain't gonna hit much. I'd suggest you'd want to use prepared statements so you can pass all the ads shown to the function in a single hit and loop through their IDs to update.

    2) I usually work 'preferred' weighting systems by having my random number in a decent range (say 0-150) and then testing for differing 'proportions' of that number range. For example, using 0-150, you could work it as follows:

    0-10 -> Ads weighted 1
    11-30 -> Ads weighted 2
    31-60 -> Ads weighted 3
    61-100 -> Ads weighted 4
    101-150 -> Ads weighted 5

    This works quite well and is simple to implement. In this way, the '5' ads have a 33% chance of showing, the '1' ads only... er... 7.3%. If you need a finer granularity you can just add ranges/change the range, etc.

    3) To be honest, off the top of my head, I can't think of a better way to do this, although it seems a little 'intensive'. IF you did go this way, I'd look to keep the rows to a minimum, i.e. only create a row if a particular ad is actually shown that day, update existing rows rather than create new ones for the same day and so on. One thing that'll be interesting/painful is how you define a 'day'. Obviously 3am here in the UK is not necessarily the same 'day' in the US.

    Hope some of this helps.

    Jon
     
    Cobnut, Feb 13, 2008 IP
  3. sarahk

    sarahk iTamer Staff

    Messages:
    28,900
    Likes Received:
    4,555
    Best Answers:
    123
    Trophy Points:
    665
    #3
    It might be an idea to download openads and see their sequencing etc. Their system is used by some pretty big sites and they will have thought all the performance issues through. You can leverage off their research and still build your high performance system.
     
    sarahk, Feb 13, 2008 IP