0

I am working on a small web application for a friend and am thinking about using a plain text file instead of MySQL, it just seems like a bit too much for the simplicity of this application.

The application will basically let people put their name on a list from a web form. There will likely be about 30-100 people putting their names on the list at a time, maybe sometimes upward of 200-300. Once all the names are entered the submission form will be closed and a single user will view the list and probably erase it soon afterwards.

What I am curious about is if there could be any issues with a lot of people trying to put their names on the list at the same time. If somebody submits a name while the server is in the middle of writing to the file, will this cause the second person's submission to fail since the file is in use already, or will the server wait for one submission to be finished before starting another?

Ben Everard
  • 13,652
  • 14
  • 67
  • 96
Alex
  • 671
  • 3
  • 11
  • 25
  • 2
    If Mysql is too much and you are concerned about concurrent commits, maybe sqlite would be appropriate. – RockyFord Jun 08 '12 at 10:09
  • 2
    .:i recommend you use database instead. your datas is safer with db. – sephoy08 Jun 08 '12 at 10:09
  • I support the advice to use a real database. The more you get used to them, the less they will seem as "a bit too much", even for small tasks. And lots of small tasks don't stay small forever. – lanzz Jun 08 '12 at 10:17
  • I suppose that's true and I am quite used to using them. My main issue is that I'm not sure exactly how the server that the application will be running on is set up. I will have to find out exactly what I have permission to do in regards to MySQL databases, and I didn't really want to bother with that if it turned out I could use a simple list. – Alex Jun 08 '12 at 10:19

2 Answers2

1

No, it will not wait, google for "race condition". If there is not much traffic on the submission form, that will not hurt, but I would recommend to use a mysql anyway, because the effort is quite the same.

Oliver
  • 2,864
  • 1
  • 16
  • 27
  • I was afraid that would be the case, but was unsure exactly how PHP handled that situation. I will just have to discuss it with the owner of the server and find out if it will be acceptable to use MySQL. – Alex Jun 08 '12 at 10:15
0

I would use a simple text file and put the names line by line. Every time you enter a new name, simple get the names/lines via

$array_of_names = file("textfile.txt");

check if the new one already exists and if not add a new line. an exact example of that is given on http://php.net/manual/en/function.file.php

Sliq
  • 15,937
  • 27
  • 110
  • 143
  • The issue, though, is that if two or more people try to add their names at the same time all the names may not get added. Will this method prevent that problem? – Alex Jun 08 '12 at 10:56
  • @Alex There is no such thing as "same time" in web development. All the action are done one after one, so no need to think about that. For more info read this http://en.wikipedia.org/wiki/Atomicity_(database_systems) – Sliq Jun 08 '12 at 11:42