PHP Doku:: Acquires an exclusive lock on a given key - function.wincache-lock.html

Verlauf / Chronik / History: (1) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzDas Verhalten von PHP beeinflussenWindows Cache for PHPWinCache Funktionenwincache_lock

Ein Service von Reinhard Neidl - Webprogrammierung.

WinCache Funktionen




(PECL wincache >= 1.1.0)

wincache_lock Acquires an exclusive lock on a given key


bool wincache_lock ( string $key [, bool $isglobal = false ] )

Obtains an exclusive lock on a given key. The execution of the current script will be blocked until the lock can be obtained. Once the lock is obtained, the other scripts that try to request the lock by using the same key will be blocked, until the current script releases the lock by using wincache_unlock().


Using of the wincache_lock() and wincache_unlock() can cause deadlocks when executing PHP scripts in a multi-process environment like FastCGI. Do not use these functions unless you are absolutely sure you need to use them. For the majority of the operations on the user cache it is not necessary to use these functions.



Name of the key in the cache to get the lock on.


Controls whether the scope of the lock is system-wide or local. Local locks are scoped to the application pool in IIS FastCGI case or to all php processes that have the same parent process identifier.


Gibt bei Erfolg TRUE zurück. Im Fehlerfall wird FALSE zurückgegeben.


Beispiel #1 Using wincache_lock()

if (
wincache_lock(“lock_txt_lock”)) { // do an exclusive lock
ftruncate($fp0); // truncate file
fwrite($fp"Write something here\n");
wincache_unlock(“lock_txt_lock”); // release the lock
} else {
"Couldn't get the lock!";

Siehe auch

Ein BenutzerBeitrag:
- Beiträge aktualisieren...
donraman at microsoft dot com
24.04.2010 3:11
User should be aware that character '\' is not allowed as part of lock name. The reason why backslash is not allowed is because we are using CreateMutex call as described at As per this article third parameter cannot have '\' character which is the lock name.

This means below code will not work.


= wincache_lock("C:\WINDOWS\Temp/cache");
$ret_val . '<br>';
$ret_val = wincache_unlock("C:\WINDOWS\Temp/cache");
$ret_val . '<br>';


PHP Powered Diese Seite bei
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)