SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using mysql vs static files?

    I am in the process of redesigning my own, in house, url shortener / redirection script using PHP with MySQL.

    The original design used PHP to query the DB(database) based on an input url. Then, matched its corresponding redirection url. Next, the redirection url was returned to the PHP script for redirection.

    I have rudimentary MySQL and PHP skills. It is my understanding that there are potential performance issues with the many DB calls.

    For this reason, it occurred to me how to negate the need to make a DB queries for redirection if I:

    1. Designate a folder to contain static redirection files. Let's call this folder "redirect".
    2. Have the PHP script write a static file to the "redirect" folder that is the name of the input url. For example, if the input url was "example.com/wert" the file in the "redirect" folder would be "wert.php".
    3. "Wert.php" would contain a PHP redirect to the redirection url.

    The DB would still be used for storing meta information, ecetera, it just would not be involved in the redirection.

    Would this be a good ideal?

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,067
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    I believe that opening and reading a file takes about 7ms on a "normal" (7200 RPM, 16MB cache) Hard disk while MySQL queries usually take less than that.
    Of course it also depends on the indices you use in MySQL. If the column containing the URL part you're looking for (e.g. "wert") is not in any index MySQL has to scan the whole table, which may take longer than using files. If you do however use an index my previous statements holds and I think MySQL would be the faster way to do it.

    I'd say MySQL would be the way to go, but I could be wrong ...
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2008
    Posts
    1,149
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd go with MySQL. You're doing a exact match lookup of a short string in a database of many and many entries, and databases are designed to do that well.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •