wincache_lock
(PECL wincache >= 1.1.0)
wincache_lock — Acquires an exclusive lock on a given key
Description
$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.
Parameters
-
key
-
Name of the key in the cache to get the lock on.
-
isglobal
-
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.
Return Values
Returns TRUE
on success or FALSE
on failure.
Examples
Example #1 Using wincache_lock()
<?php
$fp = fopen("/tmp/lock.txt", "r+");
if (wincache_lock(“lock_txt_lock”)) { // do an exclusive lock
ftruncate($fp, 0); // truncate file
fwrite($fp, "Write something here\n");
wincache_unlock(“lock_txt_lock”); // release the lock
} else {
echo "Couldn't get the lock!";
}
fclose($fp);
?>
See Also
- wincache_unlock() - Releases an exclusive lock on a given key
- wincache_ucache_set() - Adds a variable in user cache and overwrites a variable if it already exists in the cache
- wincache_ucache_get() - Gets a variable stored in the user cache
- wincache_ucache_delete() - Deletes variables from the user cache
- wincache_ucache_clear() - Deletes entire content of the user cache
- wincache_ucache_exists() - Checks if a variable exists in the user cache
- wincache_ucache_meminfo() - Retrieves information about user cache memory usage
- wincache_ucache_info() - Retrieves information about data stored in the user cache
- wincache_scache_info() - Retrieves information about files cached in the session cache
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Изменение поведения PHP
- Windows Cache for PHP
- wincache_fcache_fileinfo
- wincache_fcache_meminfo
- wincache_lock
- wincache_ocache_fileinfo
- wincache_ocache_meminfo
- wincache_refresh_if_changed
- wincache_rplist_fileinfo
- wincache_rplist_meminfo
- wincache_scache_info
- wincache_scache_meminfo
- wincache_ucache_add
- wincache_ucache_cas
- wincache_ucache_clear
- wincache_ucache_dec
- wincache_ucache_delete
- wincache_ucache_exists
- wincache_ucache_get
- wincache_ucache_inc
- wincache_ucache_info
- wincache_ucache_meminfo
- wincache_ucache_set
- wincache_unlock
Коментарии
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 http://msdn.microsoft.com/en-us/library/ms682411(VS.85).aspx. As per this article third parameter cannot have '\' character which is the lock name.
This means below code will not work.
<?php
$ret_val = wincache_lock("C:\WINDOWS\Temp/cache");
echo $ret_val . '<br>';
$ret_val = wincache_unlock("C:\WINDOWS\Temp/cache");
echo $ret_val . '<br>';
?>
The external link was off and the backslash "\" most of time are used for "scape character". Anyway, regards.