Jump to content

Server Load?


astralaaron

Recommended Posts

I have a couple programs that auto update, like chat programs etc. Some web hosts do not allow them. My question is about a comparison between checking a table in a database for a number and checking a file for a number.How do they compare? is connecting to mysql much more of a load on the server than opening a text file? In my mind it sounds like it is.. I was wondering what you guys had to say about it?how much more efficient is it to check a text file compared to checking mysql is basically what I am wondering.

Link to comment
Share on other sites

Just "blindly" opening and then reading/writing the file is faster than a database, because there is an overhead in the creation of the connection, the compilation of the query, and in the formatting of the result set (besides, databases, in the end, also read/write data from/to files...).However, when you want to search for a specific data in a potentially large data set, databases are waaaay more efficient, as they store data in a compact, optimized for searching form.There's also the issue of concurrency. A database is made to accept multiple connections to it, allowing more than a single script instance to both read and write data in the database.So, in conclusion - for a chat application and/or a program where you need to search for a specific number, using a database would most likely be the better solution.

Link to comment
Share on other sites

Just "blindly" opening and then reading/writing the file is faster than a database, because there is an overhead in the creation of the connection, the compilation of the query, and in the formatting of the result set (besides, databases, in the end, also read/write data from/to files...).However, when you want to search for a specific data in a potentially large data set, databases are waaaay more efficient, as they store data in a compact, optimized for searching form.There's also the issue of concurrency. A database is made to accept multiple connections to it, allowing more than a single script instance to both read and write data in the database.So, in conclusion - for a chat application and/or a program where you need to search for a specific number, using a database would most likely be the better solution.
I understand. What happens if one person trys to write to a file as another opens it to read? or both write at the same time? will they get an error? would fwrite return false with no error? or will the file just not be written to?
Link to comment
Share on other sites

I understand. What happens if one person trys to write to a file as another opens it to read? or both write at the same time? will they get an error? would fwrite return false with no error? or will the file just not be written to?
Depends on how each script opens up the file. If both try to open it up in "read and write" mode, the second access to it will be denied (completely; no reading nor writing). If the file is opened for just reading or just writing, any writing attempts from a second script will fail.
Link to comment
Share on other sites

Depends on how each script opens up the file. If both try to open it up in "read and write" mode, the second access to it will be denied (completely; no reading nor writing). If the file is opened for just reading or just writing, any writing attempts from a second script will fail.
I should have made it more clear, my main concern is will it output an error if it cannot read or write to the file?
Link to comment
Share on other sites

You will get the error when you try to open the file.http://www.php.net/manual/en/function.fopen.php

Errors/ExceptionsIf the open fails, an error of level E_WARNING is generated. You may use @ to suppress this warning.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...