<p>I'm trying to update a variable in APC, and will be many processes trying to do that.</p>

<p>APC doesn't provide locking functionality, so I'm considering using other mechanisms... what I've found so far is mysql's GET_LOCK(), and php's flock(). Anything else worth considering?</p>

<p>Update: I've found sem_acquire, but it seems to be a blocking lock.</p>

If you don't mind basing your lock on the filesystem, then you could use fopen() with mode 'x'. Here is an example:
```
```
$f = fopen("lockFile.txt", 'x');
if($f) {
    $me = getmypid();
    $now = date('Y-m-d H:i:s');
    fwrite($f, "Locked by $me at $now\n");
    fclose($f);
    doStuffInLock();
    unlink("lockFile.txt"); // unlock        
}
else {
    echo "File is locked: " . file_get_contents("lockFile.txt");
    exit;
}
```
```
See www.php.net/fopen