Another irritating noob question, I'm afraid ! - Say that two or more users are running the same PHP script on my server from different locations. Is there any system-wide variable which I can set which is accessible to all, and which I can utilise to determine the lock status for a file ? (Ie: avoiding attempted simultaneous 'write' operations with a while loop in the script) - Thanks, guys. You seem to be patient with beginners. - Chris
Thanks, sillysoft. - I saw that in the manual and was put off by the warnings about it possibly not working across multiple scripts running on the same server. How serious a warning is that if I have, say, 500 concurrent users on my server, all running a script called registerCust.php, and all wanting the customer username/password file ? - I only intend to lock/unlock ONE file, which will be a control file containing records which give the lock status of all the other files in my database. Once locked/unlocked status is inside a file record in the control, it's not vulnerable to corruption. Users can simply loop until they can get at the control file to find out whether they can read/write to the file the script wants to modify. The problem is locking/unlocking the control, itself, and this is what prompted my original post. - If anyone has solved this by means of devious logic and a globally- accessible persistent system variable, rather than the use of a filesystem function which may fail if stressed, I'd love to hear. - ps: My background is in FilemakerPro, C and some Perl. - Chris
Are you using flatafile database? How about creating a "lock" file ... used to do this with OpenVMS back in the days!!! eg script trying to update "filename.txt" would check if "filename.lock" exists ... if it does wait a sec and then check again ... create "filename.lock", update "filename.txt" with data and then delete "filename.lock" ... I think the danger with a while loop would be, if you have 500 scripts running simultaneously they may all try and create the lock file at the same time ... Why not use mySQL ... (I might be wrong but) maybe tehn you wouldn't need to worry about this ???
are u using PHP File Functions? If yes, take a look at flock() php.net/flock sorry i am not allowed to post link yet
I can see you're from the same era as me. Ah, happy days ! I got quite used to writing flat textfile databases in CBasic under CP/M and doing all my own indexing with trees read into arrays ........ [pauses to put on Glenn Miller record and brown slippers ..] But, the individual lockfile idea is a good one. I'll pee around with some code and see what I get. I don't use SQL, mainly because (even after a good few years of this) I actually enjoy getting code to do quite low-level stuff ! Thanks for the tip. - Chris