1

i am trying to write in txt file and my data are comma separated numbers which are appended every time. i have two types of data which i am trying to compare so if we are using one txt file then it has to be written in new line .

   1,5,10,15,22,32

other line is

   1,5,7,12,8,99

so its simple data but with time it grows as new data are appended and in worst situation may become big. may be 10-15000 numbers in each line i have also doubt that if these txt files are open and closed fast enough data may corrupt. so i would like to write these two lines in two different txt file instead of one. where is more integrity and performance ??

should i use only one file or two files are preferred. dont want to use database as database is always naughty and may create some load on server which can be avoided with txt file

Steeve
  • 423
  • 2
  • 9
  • 23
  • 1
    "*as database is always naughty*"... You *may* want to use a database for this purpose, operating with file read/write is always an heavy operation when you are handling a lot of data. – Alberto Oct 10 '18 at 14:55
  • @Alberto i dont think read write may cause any load on server but sql will defenitely – Steeve Oct 10 '18 at 14:56
  • 2
    Out of curiosity, what do you think databases do other than store things in files? They can manage locking a lot better than you can, I promise. – iainn Oct 10 '18 at 14:56
  • Steeve, if you *don't think*, do as you prefer :) – Alberto Oct 10 '18 at 14:57
  • @iainn totally agree that integrity of data will be much more compared to txt file but it may create load on shared server but txt file wont – Steeve Oct 10 '18 at 14:57
  • @Alberto i am talking about shared host so sorry if i was not polite – Steeve Oct 10 '18 at 14:58
  • Consider that with one file, you can't just append data to the first line without rewriting the second line. With two files, you could just append data at the end. For data integrity, you should have a look at [`flock()`](http://php.net/manual/en/function.flock.php). – Karsten Koop Oct 10 '18 at 15:15

0 Answers0