|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Ajax Application Generator Generate database and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
Looking for suggestions
A developer of a text based CMS written in php is looking for suggestions to solve a problem and I thought I would ask people here for help.
The solution must work on a windows and linux platform. The problem appears to be that the text files i.e. (members, stats, forums) will become corrupt sometimes when they are accessed or changed to to often, he is presently trying to solve the problem by locking the files to try to prevent corruption. Doesn't appear to be working correctly. So if anyone has an idea, suggestion or method on how to correct this problem please let me know. Thanks in advance!!! |
|
#2
|
|||
|
|||
|
Thoughts on record/file locking
I am very much of a beginner, and self-taught. But here are my thoughts. A while ago I was wondering what happens at a website if a php script updates a text file. I was wondering what happens if several people come to a site at once and try to open/update the same file. It seems obvious to me that updates to a record in a mysql database would not be corrupted, since each client would be accessing the same mysql engine, and the engine would somehow queue the requests, and update the record in an orderly fashion, without corrupting the record.
Some years ago, in the 1980's I asked a unix programmer about record locking issues. He laughed in a somewhat scoffing manner, and then, after thinking for a moment, commented that and empty file would be created by the record for each record accessed, and that other users or processes would first test for the existence of that file. If the file (whose name perhaps is the record key) did exist, then a message would be issued stating that the record was in use, and to try later. Once the original application finished with that record, it would delete the empty file, and by this fashion, other applications/users would know that the record was now "unlocked". Perhaps such a scheme might be useful in this situation. A php application could create an empty file which would indicate that the other file was being updated. Once the update is finished and the file is closed, then the "flag" file could be deleted. It would certainly be interesting if this type of tactic actually eliminated the file corruption. A different thought would be to switch from a file to a blob field in a mysql record. I imagine that one should be able to store the same sorts of things in a large field in a mysql row that one stores in a simple text file. In this way, one would depend upon the mysql engine itself to maintain read/write/update file integrity. |
|
#3
|
|||
|
|||
|
If this is indeed the problem, which I have to confess to being doubtful of without some further explanation of what is going on and perhaps some code, then the suggestion above should work if implemented properly but it suffers from a major flaw.
Lets assume two clients are attempting to access the file at the same time. In an ideal world the first client checks for the flag file, finds there isn't one and creates it then the second client will discover it exists if it runs the test. Unfortunately this will not always be the case since the first client may run the test, then the second one may run the test before the flag file is created meaning they both think they can have access to the main file. To solve this problem you need to implement something that works indivisibly for both the test and setting of the flag in whatever form it takes. Ie nothing can happen in between the test being run and the flag being set. Whether this is the case or not with the scheme described above I don't know, but if this is the problem then you will need to find out before implementing something otherwise this problem will reoccur later and be even harder to locate since it will happen intermitently depending on the timings of the accesses. Hope this helps, -KM- |
|
#4
|
|||
|
|||
|
Hi
Here is the snipet of code being used to attemp to control the text files, one of the draw backs I have noticed is when a file get locked it appears to stay locked, if anyone can suggest a better way or an improvement to this code, that would be great. Again thanks in advance. PHP Code:
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > Looking for suggestions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|