Click to See Complete Forum and Search --> : Multiple users writing to file
Da Warriah
02-10-2006, 08:32 AM
I have a question about using a flatfile system versus a MySQL database system with PHP. I'm creating a site that I hope will have a high volume of traffic (maybe not, but I can hope anyway), and because of the nature of the site, it will likely have a high amount of reading and writing to a database or other such system. But I was wondering: what happens if two users write to a file from the same PHP script at almost exactly the same time? Will one user's changes be overwritten, or will they be processed in order? And the same with the database - what happens if two people are writing to the database at the same time? Do they get processed one after the other or at the same time?
Thank you in advance. :)
Oh and one other theoretical-type question: Would it be easier to write to the database/flatfile system every time the users make a change, or would it be best to store all their changes using some sort of cookie or session and then write it all at the same time? Thanks.
NogDog
02-10-2006, 09:55 AM
It's probably "safer" to use a DB for this, as MySQL has built-in locking/queueing functionality specifically for handling this type of thing. For tables that will have a lot of inserts and/or updates, you probably should consider making them INNODB-type tables (instead of the usual MyISAM type), as INNODB supports row-level locking, while MyISAM only locks at the table level. (MyISAM will be faster though for tables which are primarily only used for SELECT queries and don't have as much update activity.)
I would think that where practical and logical to do so, I would store interim information in a session array and then update the database at the conclusion of the process; but I wouldn't say that's a hard and fast rule.
Da Warriah
02-10-2006, 03:20 PM
Thank you very much for the prompt response. I suppose I will then look into the INNODB option - I've been having to brush up on my limited MySQL skills lately...
bokeh
02-10-2006, 03:48 PM
Although there may be one, I can't think of a single reason why anyone that has access to MySQL would consider using a flatfile database system.
SpectreReturns
02-10-2006, 04:29 PM
Too lazy to learn SQL?
Da Warriah
02-11-2006, 09:30 AM
Although there may be one, I can't think of a single reason why anyone that has access to MySQL would consider using a flatfile database system.
Because I have much more experience with flatfile systems than with MySQL? That means that it takes me twice as long to do anything, because I'm constantly checking the MySQL documentation and such trying to figure out how to do such-and-such...but anyways, I'll stumble through it...
Sheldon
02-11-2006, 09:45 PM
haha lets slander the non-sql user.
Jokes aside with no harm attended. I agree with every one here, a mySQL databse would be alot eiser/safer and better.
bokeh
02-12-2006, 03:36 AM
Because I have much more experience with flatfile systems than with MySQL?Basic SQL is pretty simple. If you were starting from scratch you could learn to do more in a day with SQL than you could learn in a month using flatfiles.