Pull data from a File or MySQL, Which is Faster?

Discussion in 'Programming' started by RogerDodgr, May 25, 2010.

  1. #1
    I need to update about ten lines of code on my front page every day. I want to do this with a php include statement but I am not sure what is the best to gather the data. I can code it in one of two ways: MySQL or parse if off a text file uploaded to server. My question is Which is quicker, a text file or a call to MySQL? I want my home page to load fast.
     
    Last edited: May 25, 2010
    RogerDodgr, May 25, 2010 IP
  2. Cozmic

    Cozmic Member

    Messages:
    146
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    48
    #2
    I would expect that the database would be faster. Either way, it probably wouldn't take very long with just a few queries, though.
     
    Cozmic, May 25, 2010 IP
  3. windy

    windy Active Member

    Messages:
    1,093
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    78
    #3
    use database if too many data, otherwise use text file
     
    windy, May 26, 2010 IP
  4. flexdex

    flexdex Peon

    Messages:
    104
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes, it really depends on how many data is at the text file and how complex is it to parse.

    Further i would take in account; if you do not need a database at all at your site then setting up or pay a database just for such a little feature is wasting money. I would prefer flat files in that case.
     
    flexdex, May 26, 2010 IP
  5. CaseyM

    CaseyM Peon

    Messages:
    289
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Completly depends on the amount of data that you need to display. However, even if you don't need to display alot of data, instead of a textfile, you should use XML which is much more structured.
     
    CaseyM, May 26, 2010 IP
  6. bibinsmk

    bibinsmk Active Member

    Messages:
    205
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #6
    If the data is very less then u can use text file other wise database is the best option. For the later expansions database will be the best choice.
     
    bibinsmk, May 26, 2010 IP
  7. trevHCS

    trevHCS Peon

    Messages:
    40
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Depends what you mean by parsing the code - this HTML or Jscript that's going to be stored? If so then I'd imagine the text file would be vastly faster in most cases especially for 10 lines as imagine the difference.

    - On the one hand you've got a database where PHP needs to make a connection (authentication etc)., wait for the database to perform the query, process the query in the database and then send all the data back via the API so that PHP can sort it into variables.

    - On the other PHP makes a system call to say "read X file" which is usually a pretty optimised operation especially for regular requests (file-caching and such). The OS finds the file, passes it back as a stream to PHP which drops it into a variable and bingo there you've got it.

    Reading off a disk is very, very fast for a server and some might even keep the file in memory cache as well as caching the fact that it exists so even quicker. Forgot to add - the above assumes you're using something like MySQL as the database. It might be a bit quicker with SQLLite or similar as they're more flat file, but still not sure it'd really improve load times vs just reading from a disk.

    Trev
     
    Last edited: May 27, 2010
    trevHCS, May 27, 2010 IP
  8. cupi

    cupi Greenhorn

    Messages:
    54
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #8
    Both are almost equally the same. The difference is that once you get more data it's easier to manage that data with a database rather than a file system. So for the long run, go with the MySQL database.
     
    cupi, May 27, 2010 IP
  9. Lord

    Lord Active Member

    Messages:
    134
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #9
    database access is faster than txt access, but this is important only for major data

    if you only have 1kb of data, stick to txt or how someone before said, xml
     
    Lord, May 27, 2010 IP
  10. diveloper

    diveloper Active Member

    Messages:
    171
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #10
    SQL has to be quicker....even though you may not notice it, depending on the amount of data
     
    diveloper, Jun 1, 2010 IP