mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2025-06-18 13:57:03 +08:00
116 lines
7.7 KiB
HTML
116 lines
7.7 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||
<html>
|
||
<head>
|
||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||
<title>Acquires an exclusive lock on a given key</title>
|
||
</head>
|
||
<body class="docs"><div id="layout">
|
||
<div id="layout-content"><div id="function.wincache-lock" class="refentry">
|
||
<div class="refnamediv">
|
||
<h1 class="refname">wincache_lock</h1>
|
||
<p class="verinfo">(PECL wincache >= 1.1.0)</p><p class="refpurpose"><span class="refname">wincache_lock</span> — <span class="dc-title">
|
||
Acquires an exclusive lock on a given key
|
||
</span></p>
|
||
|
||
</div>
|
||
<div class="refsect1 description" id="refsect1-function.wincache-lock-description">
|
||
<h3 class="title">说明</h3>
|
||
<div class="methodsynopsis dc-description">
|
||
<span class="methodname"><strong>wincache_lock</strong></span>
|
||
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$key</code></span>
|
||
[, <span class="methodparam"><span class="type">bool</span> <code class="parameter">$isglobal</code><span class="initializer"> = <strong><code>FALSE</code></strong></span></span>
|
||
] ) : <span class="type">bool</span></div>
|
||
|
||
<p class="para rdfs-comment">
|
||
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 <span class="function"><a href="wincache_unlock.html" class="function">wincache_unlock()</a></span>.
|
||
</p>
|
||
<div class="warning"><strong class="warning">Warning</strong>
|
||
<p class="simpara">
|
||
Using of the <span class="function"><strong>wincache_lock()</strong></span> and <span class="function"><a href="wincache_unlock.html" class="function">wincache_unlock()</a></span> 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.
|
||
</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="refsect1 parameters" id="refsect1-function.wincache-lock-parameters">
|
||
<h3 class="title">参数</h3>
|
||
<p class="para">
|
||
<dl>
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">key</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
Name of the key in the cache to get the lock on.
|
||
</p>
|
||
</dd>
|
||
|
||
|
||
|
||
<dt>
|
||
<code class="parameter">isglobal</code></dt>
|
||
|
||
<dd>
|
||
|
||
<p class="para">
|
||
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.
|
||
</p>
|
||
</dd>
|
||
|
||
|
||
</dl>
|
||
|
||
</p>
|
||
</div>
|
||
|
||
<div class="refsect1 returnvalues" id="refsect1-function.wincache-lock-returnvalues">
|
||
<h3 class="title">返回值</h3>
|
||
<p class="para">
|
||
成功时返回 <strong><code>TRUE</code></strong>, 或者在失败时返回 <strong><code>FALSE</code></strong>。
|
||
</p>
|
||
</div>
|
||
|
||
<div class="refsect1 examples" id="refsect1-function.wincache-lock-examples">
|
||
<h3 class="title">范例</h3>
|
||
<p class="para">
|
||
<div class="example" id="example-612">
|
||
<p><strong>Example #1 Using <span class="function"><strong>wincache_lock()</strong></span></strong></p>
|
||
<div class="example-contents">
|
||
<div class="phpcode"><pre><span style="color: #000000">
|
||
<span style="color: #0000BB"><?php<br />$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">"/tmp/lock.txt"</span><span style="color: #007700">, </span><span style="color: #DD0000">"r+"</span><span style="color: #007700">);<br />if (</span><span style="color: #0000BB">wincache_lock</span><span style="color: #007700">(</span><span style="color: #0000BB">“lock_txt_lock”</span><span style="color: #007700">)) { </span><span style="color: #FF8000">// do an exclusive lock<br /> </span><span style="color: #0000BB">ftruncate</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #0000BB">0</span><span style="color: #007700">); </span><span style="color: #FF8000">// truncate file<br /> </span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">, </span><span style="color: #DD0000">"Write something here\n"</span><span style="color: #007700">);<br /> </span><span style="color: #0000BB">wincache_unlock</span><span style="color: #007700">(</span><span style="color: #0000BB">“lock_txt_lock”</span><span style="color: #007700">); </span><span style="color: #FF8000">// release the lock<br /></span><span style="color: #007700">} else {<br /> echo </span><span style="color: #DD0000">"Couldn't get the lock!"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span>
|
||
</span>
|
||
</pre></div>
|
||
</div>
|
||
|
||
</div>
|
||
</p>
|
||
</div>
|
||
|
||
|
||
<div class="refsect1 seealso" id="refsect1-function.wincache-lock-seealso">
|
||
<h3 class="title">参见</h3>
|
||
<p class="para">
|
||
<ul class="simplelist">
|
||
<li class="member"><span class="function"><a href="wincache_unlock.html" class="function" rel="rdfs-seeAlso">wincache_unlock()</a> - Releases an exclusive lock on a given key</span></li>
|
||
<li class="member"><span class="function"><a href="wincache_ucache_set.html" class="function" rel="rdfs-seeAlso">wincache_ucache_set()</a> - Adds a variable in user cache and overwrites a variable if it already exists in the cache</span></li>
|
||
<li class="member"><span class="function"><a href="wincache_ucache_get.html" class="function" rel="rdfs-seeAlso">wincache_ucache_get()</a> - Gets a variable stored in the user cache</span></li>
|
||
<li class="member"><span class="function"><a href="wincache_ucache_delete.html" class="function" rel="rdfs-seeAlso">wincache_ucache_delete()</a> - Deletes variables from the user cache</span></li>
|
||
<li class="member"><span class="function"><a href="wincache_ucache_clear.html" class="function" rel="rdfs-seeAlso">wincache_ucache_clear()</a> - Deletes entire content of the user cache</span></li>
|
||
<li class="member"><span class="function"><a href="wincache_ucache_exists.html" class="function" rel="rdfs-seeAlso">wincache_ucache_exists()</a> - Checks if a variable exists in the user cache</span></li>
|
||
<li class="member"><span class="function"><a href="wincache_ucache_meminfo.html" class="function" rel="rdfs-seeAlso">wincache_ucache_meminfo()</a> - Retrieves information about user cache memory usage</span></li>
|
||
<li class="member"><span class="function"><a href="wincache_ucache_info.html" class="function" rel="rdfs-seeAlso">wincache_ucache_info()</a> - Retrieves information about data stored in the user cache</span></li>
|
||
<li class="member"><span class="function"><a href="wincache_scache_info.html" class="function" rel="rdfs-seeAlso">wincache_scache_info()</a> - Retrieves information about files cached in the session cache</span></li>
|
||
</ul>
|
||
</p>
|
||
</div>
|
||
|
||
|
||
</div></div></div></body></html> |