Jump to content

Counter LOCK~~~


jimmyyami

Recommended Posts

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;

}

 

.........

 

}

// ----------------------------------------------------------------------------

 

Link to comment
https://forums.phpfreaks.com/topic/71760-counter-lock~~~/#findComment-366776
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.