astralaaron Posted February 20, 2010 Share Posted February 20, 2010 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 More sharing options...
boen_robot Posted February 20, 2010 Share Posted February 20, 2010 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 More sharing options...
astralaaron Posted February 21, 2010 Author Share Posted February 21, 2010 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 More sharing options...
boen_robot Posted February 21, 2010 Share Posted February 21, 2010 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 More sharing options...
astralaaron Posted February 22, 2010 Author Share Posted February 22, 2010 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 More sharing options...
Synook Posted February 22, 2010 Share Posted February 22, 2010 You will probably get a warning. Link to comment Share on other sites More sharing options...
astralaaron Posted February 22, 2010 Author Share Posted February 22, 2010 You will probably get a warning.would throwing in an @ in front of fwrite stop that warning? Link to comment Share on other sites More sharing options...
Synook Posted February 22, 2010 Share Posted February 22, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.