stylusrose Posted April 29, 2008 Share Posted April 29, 2008 I was trying to write a script that outputs to a file. the problem is, I don't want more than one user to be able to run that script at time. I know, mysql would probably be a better idea. But I'm just tinkering around with ideas. So, is there anyway to prevent a user to access a script whilst it is in use? Quote Link to comment Share on other sites More sharing options...
skatermike21988 Posted April 29, 2008 Share Posted April 29, 2008 you can use mysql and then an if statement like if($inuse=="yes") { echo"Sorry the file is currently in use, please try again later"; } else { //DISPLAY DATA HERE } And then have like a cron job script run to where if the last time it was used was 10 mins ago or so, it clears the mysql, just incase the user exits his/her browser, and have a link to exit, so that way it clears the data. I know it sounds kinda confusing but I haven't been to sleep yet, so hope this helps Quote Link to comment Share on other sites More sharing options...
stylusrose Posted April 29, 2008 Author Share Posted April 29, 2008 hehe... I was actually wondering if there was a way to do it without mysql 0___0 Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 29, 2008 Share Posted April 29, 2008 Look into the flock() function. http://us2.php.net/manual/en/function.flock.php Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 29, 2008 Share Posted April 29, 2008 You can use the flock() function. At the start of the script, do <?php $fp = fopen('dummy.file','w'); if (flock($fp, LOCK_EX)) { // // do your work // } else { // issue the error message } fclose($fp); ?> Ken (beaten to it) Quote Link to comment Share on other sites More sharing options...
stylusrose Posted April 29, 2008 Author Share Posted April 29, 2008 oh, well that was easy o.o; thanks! ^.^ Quote Link to comment 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.