How URL shortening scripts work?

Discussion in 'PHP' started by olddocks, Sep 30, 2009.

  1. #1
    olddocks, Sep 30, 2009 IP
  2. devji

    devji Peon

    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    A lot simpler than I thought. You'd need a fast server to handle all the requests and you'll also need to check whether a URL already exists in the database.

    A website like TinyURL must receive so many links that they must have to clear old links after some time. Does anyone know how long the links are active for?
     
    devji, Oct 1, 2009 IP
  3. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I would say they have a counter system in place, to delete links under there own terms.
     
    pixmania, Oct 1, 2009 IP
  4. Pudge1

    Pudge1 Well-Known Member

    Messages:
    912
    Likes Received:
    6
    Best Answers:
    1
    Trophy Points:
    140
    Digital Goods:
    1
    #4
    Its easier just to tell it to make a new folder with a HTML document containing a redirect.
     
    Pudge1, Oct 1, 2009 IP
  5. devji

    devji Peon

    Messages:
    31
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    True. I guess it would be very easy to set up a cron job to do that. What would be a useful feature is if you could set how long you'll need the link to be active for. e.g. if I'm PM'ing you a link, it would only need to be active for a short time whereas if a magazine is printing a shortened URL, it would need to be active for much longer.
     
    devji, Oct 1, 2009 IP
  6. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Uh, I don't think tinyurl or any other big url shortener should ever delete links.. That would result in a very bad user experience because those links aren't deleted from all over the web and would result in 404 not founds.
     
    premiumscripts, Oct 1, 2009 IP
  7. olddocks

    olddocks Notable Member

    Messages:
    3,275
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    215
    #7
    As the no of URLs you store reach millions, your database alone would be many GB in size. In that case your server will be slow. Of course you have to check the duplicates and redundant data.

    It is unlikely that they would delete the link, but can disable redirecting to destination URL.
     
    olddocks, Oct 1, 2009 IP
  8. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #8

    Maybe, but I was referring to well out dated links, the kind people make before they start to use the services for real, ie: if a link generated 2 or 3 hits on the day it was created, 2 years ago, that kind of link could safely be removed. Or even a link generated 5 years ago, that hasn't received any hits in the last 2.

    404 not founds, not to many of those around, most use the 404 htaccess tricks these days or something similar.
     
    pixmania, Oct 1, 2009 IP
  9. w47w47

    w47w47 Peon

    Messages:
    255
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    just just put the long url into mysql and some other filed with ID for example and then you give out just the ID from mysql and the link has just the id in the url instead of the long url... just an example.. :>
     
    w47w47, Oct 1, 2009 IP
  10. pixmania

    pixmania Peon

    Messages:
    229
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Heres a site that implements that very idea. http://teeny.im/ see advanced settings.
     
    pixmania, Oct 2, 2009 IP