Is fwrite faster than using Mysqli?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott

    Is fwrite faster than using Mysqli?

    Hi,

    Which is faster writing to a file using fwrite or is using a
    database to store data? I want to create a log file and it does not
    matter if it is in a text file or on a database. I just want the one
    that is easier on the server. Any advice is greatly appreciated.

    --
    Your friend,
    Scott


    Sent to you from a Linux computer using Kubuntu Version 8.10


    ----== Posted via Pronews.Com - Unlimited-Unrestricted-Secure Usenet News==----
    http://www.pronews.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
    ---= - Total Privacy via Encryption =---
  • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

    #2
    Re: Is fwrite faster than using Mysqli?

    Scott escribió:
    Which is faster writing to a file using fwrite or is using a
    database to store data? I want to create a log file and it does not
    matter if it is in a text file or on a database. I just want the one
    that is easier on the server. Any advice is greatly appreciated.
    If you're worried about performance recommend you do your own
    benchmarks. You can use microtime(TRUE) to measure times with
    microseconds, it's rather straightforward .

    In any case, intuition says that appending a line at the end of a file
    should be faster that going through the overload of a database
    management system which, in the end, will write it into a file.
    Databases are chosen when you have other considerations like storing
    large amount of data, querying existing data o handling concurrent writings.


    --
    -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
    -- Mi sitio sobre programación web: http://bits.demogracia.com
    -- Mi web de humor al baño María: http://www.demogracia.com
    --

    Comment

    • ursynek

      #3
      Re: Is fwrite faster than using Mysqli?

      And where you think are writing data, when you use database?
      hint: database is storage in file.

      PS. sorry for my language :P

      Scott pisze:
      Hi,
      >
      Which is faster writing to a file using fwrite or is using a
      database to store data? I want to create a log file and it does not
      matter if it is in a text file or on a database. I just want the one
      that is easier on the server. Any advice is greatly appreciated.
      >

      Comment

      • Bleak

        #4
        Re: Is fwrite faster than using Mysqli?

        On Nov 6, 11:39 pm, Scott <scle...@sgamin g.orgwrote:
        Hi,
        >
        Which is faster writing to a file using fwrite or is using a
        database to store data? I want to create a log file and it does not
        matter if it is in a text file or on a database. I just want the one
        that is easier on the server. Any advice is greatly appreciated.
        >
        --
        Your friend,
        Scotthttp://sgaming.org
        >
        Sent to you from a Linux computer using Kubuntu Version 8.10
        >
        ----== Posted via Pronews.Com - Unlimited-Unrestricted-Secure Usenet News==----http://www.pronews.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
        ---= - Total Privacy via Encryption =---

        If you want to implement a log table in MySQL (and you are interested
        in performance) you should use the <Archive storage engine>. It has
        some limitation and it could also be not installed with your server
        configuration, check the (MySQL) manual to have some information
        more.
        Otherwise you may want to consider SQlite.

        Try them out, benchmark them and choose the right one for your use.

        Comment

        • Jerry Stuckle

          #5
          Re: Is fwrite faster than using Mysqli?

          Scott wrote:
          Hi,
          >
          Which is faster writing to a file using fwrite or is using a
          database to store data? I want to create a log file and it does not
          matter if it is in a text file or on a database. I just want the one
          that is easier on the server. Any advice is greatly appreciated.
          >
          Neither is overly onerous when you're just adding data to the end. A
          text file would be faster - but mysql isn't that hard. But there are
          other reasons for using a database - like multitasking.

          Me thinketh though art prematurely optimizething.



          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • C. (http://symcbean.blogspot.com/)

            #6
            Re: Is fwrite faster than using Mysqli?

            On 6 Nov, 22:39, Scott <scle...@sgamin g.orgwrote:
            Hi,
            >
            Which is faster writing to a file using fwrite or is using a
            database to store data? I want to create a log file and it does not
            matter if it is in a text file or on a database. I just want the one
            that is easier on the server. Any advice is greatly appreciated.
            >
            --
            Your friend,
            Scotthttp://sgaming.org
            >
            Sent to you from a Linux computer using Kubuntu Version 8.10
            >
            ----== Posted via Pronews.Com - Unlimited-Unrestricted-Secure Usenet News==----http://www.pronews.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
            ---= - Total Privacy via Encryption =---
            1) why don't you test it for yourself and tell us
            2) It really it doesn't matter. You're going to have lots of problems
            using files this way if there is any chance of contention.

            Really you should be comparing using syslog() and mysqli

            C.

            Comment

            • Gordon

              #7
              Re: Is fwrite faster than using Mysqli?

              On Nov 6, 10:39 pm, Scott <scle...@sgamin g.orgwrote:
              Hi,
              >
                    Which is faster writing to a file using fwrite or is using a
              database to store data?  I want to create a log file and it does not
              matter if it is in a text file or on a database.  I just want the one
              that is easier on the server.  Any advice is greatly appreciated.
              >
              --
              Your friend,
              Scotthttp://sgaming.org
              >
              Sent to you from a Linux computer using Kubuntu Version 8.10
              >
              ----== Posted via Pronews.Com - Unlimited-Unrestricted-Secure Usenet News==----http://www.pronews.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
              ---= - Total Privacy via Encryption =---
              If you already have a connection open to a MySQL database then logging
              data to a log table probably has minimal overhead compared to opening
              a separate file, obtaining a lock, writing your log line, releasing
              the lock and closing the file. If you were connecting to the database
              with the sole intention of logging something then the file would be
              the better choice. However, the overhead of either approach shouldn't
              be enough to be noticeable to an end user.

              So my choice would be: Do you need to connect to a database anyway?

              YES: Use a DB table
              NO: Use a file

              Comment

              Working...