473,382 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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
http://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 =---
Nov 6 '08 #1
6 2291
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
--
Nov 7 '08 #2
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.
Nov 7 '08 #3
On Nov 6, 11:39 pm, Scott <scle...@sgaming.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.comThe #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.
Nov 7 '08 #4
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.
js*******@attglobal.net
==================

Nov 7 '08 #5
On 6 Nov, 22:39, Scott <scle...@sgaming.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.comThe #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.
Nov 7 '08 #6
On Nov 6, 10:39*pm, Scott <scle...@sgaming.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.comThe #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
Nov 15 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: davids58 | last post by:
trying to figure out how to use a mysql database with PHP. I ran the following code: <?php // defines database connection data define('DB_HOST', 'localhost'); define('DB_USER', 'ajaxuser');...
1
by: soft_devjava | last post by:
my environment: =========================== -php ver 5.2.0 -mysql 5 -windows xp -apache 2 -all of these are on the same machine my code: ==========================
13
by: Schmidty | last post by:
If you do a page reload with $_SERVER will your program lose a mysqli connection upon the reload of the page? Would this code work? I need to know how to carry over a connection between methods as...
21
by: Daz | last post by:
Hi everyone. I am trying to create an extension of the mysqli class within PHP, and I am finding it quite difficult. I am fairly new to PHP classes, and decided to give them a go. Here's what I...
2
by: Michael | last post by:
Hi, I try to use mysqli object instead of standard mysql functions. Is it ok to create mysqli object within my class or schould I pass mysqli object to my object. The problem is, with code...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
0
by: anonymous | last post by:
I had a tough time getting PHP to connect to MySQL using mysqli on XP. The following code from the php documentation on mysqli failed to work on xp. $mysqli = new mysqli( "localhost", "user",...
2
by: Taras_96 | last post by:
Hi everyone, I'm trying to run a number of commands stored within a sql file from within php using mysqli::query. The syntax I'm using is: source C:\data\projects\forum...
25
by: Abubakar | last post by:
Hi, recently some C programmer told me that using fwrite/fopen functions are not efficient because the output that they do to the file is actually buffered and gets late in writing. Is that...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.