jimmyyami Posted October 4, 2007 Share Posted October 4, 2007 Application.lock in ASP used widely in website's visitor Counter to prevent two people enter the site at the same time. MY question is ... how to prevent two person operate the MYSQL database exactly at the same time when the counter is based on PHP????~~ Quote Link to comment https://forums.phpfreaks.com/topic/71760-counter-lock~~~/ Share on other sites More sharing options...
fenway Posted October 4, 2007 Share Posted October 4, 2007 Don't use php based counters. Quote Link to comment https://forums.phpfreaks.com/topic/71760-counter-lock~~~/#findComment-362029 Share on other sites More sharing options...
jimmyyami Posted October 9, 2007 Author Share Posted October 9, 2007 i don't think so. there must be some other method to solve this in PHP Quote Link to comment https://forums.phpfreaks.com/topic/71760-counter-lock~~~/#findComment-365105 Share on other sites More sharing options...
fenway Posted October 9, 2007 Share Posted October 9, 2007 i don't think so. there must be some other method to solve this in PHP Why do you think you can solve a database issue with php? Quote Link to comment https://forums.phpfreaks.com/topic/71760-counter-lock~~~/#findComment-365290 Share on other sites More sharing options...
jimmyyami Posted October 10, 2007 Author Share Posted October 10, 2007 If i can't control how many people has already get entrance into the apartment. Maybe i can just guard the gate not to allow two buddy go through it at the same time??? Quote Link to comment https://forums.phpfreaks.com/topic/71760-counter-lock~~~/#findComment-366137 Share on other sites More sharing options...
fenway Posted October 10, 2007 Share Posted October 10, 2007 You can... but not with a counter... what are you actually trying to do Quote Link to comment https://forums.phpfreaks.com/topic/71760-counter-lock~~~/#findComment-366220 Share on other sites More sharing options...
jimmyyami Posted October 11, 2007 Author Share Posted October 11, 2007 flock() might is what i need. I hope... first create a lock file as the guard dog for MySQL database. use flock() made it able to open once simultaneously. and use it as the switch of this lock file. the code is something like that listed as below... // ---------------------------------------------------------------------------- $lockfile = "vclock.lock"; ..... $vclock = fopen($lockfile, "w"); if (!$vclock) { echo " lockfile $lockfile not able to open"; exit; } if (!flock($vclock, LOCK_EX)) { echo "lock $lockfile has fail"; exit; } // ---------------------------------------------------------------------------- if (!($fp=fopen($logfile,"r"))) { echo "file $logfile not able to open"; exit; } flock($fp, LOCK_SH); flock($fp, LOCK_UN); fclose($fp); ....... if (!($vcct=fopen($logfile,"w"))) { echo " lockfile $lockfile not able to open"; exit; } if (!flock($vcct, LOCK_EX)) { echo "lock file $logfile failure"; exit; } ......... } // ---------------------------------------------------------------------------- Quote Link to comment https://forums.phpfreaks.com/topic/71760-counter-lock~~~/#findComment-366776 Share on other sites More sharing options...
fenway Posted October 11, 2007 Share Posted October 11, 2007 Sure, go nuts... if you want isolation, there are database engines that support it. Quote Link to comment https://forums.phpfreaks.com/topic/71760-counter-lock~~~/#findComment-367362 Share on other sites More sharing options...
jimmyyami Posted October 12, 2007 Author Share Posted October 12, 2007 you Chinese~~ Quote Link to comment https://forums.phpfreaks.com/topic/71760-counter-lock~~~/#findComment-367615 Share on other sites More sharing options...
fenway Posted October 12, 2007 Share Posted October 12, 2007 you Chinese~~ Who, me? Nope. Quote Link to comment https://forums.phpfreaks.com/topic/71760-counter-lock~~~/#findComment-367824 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.