function.dio-fcntl.html

来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 199 行

HTML
199
字号
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>Performs a c library fcntl on fd</title>  <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.dio-close.html">dio_close</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.dio-open.html">dio_open</a></div> <div class="up"><a href="ref.dio.html">Direct IO Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.dio-fcntl" class="refentry"> <div class="refnamediv">  <h1 class="refname">dio_fcntl</h1>  <p class="verinfo">(PHP 4 &gt;= 4.2.0, PHP 5 &lt;= 5.0.5)</p><p class="refpurpose"><span class="refname">dio_fcntl</span> &mdash; <span class="dc-title">Performs a c library fcntl on fd</span></p> </div> <div class="refsect1 description">  <h3 class="title">Description</h3>  <div class="methodsynopsis dc-description">   <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><b><b>dio_fcntl</b></b></span>    ( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$fd</tt></span>   , <span class="methodparam"><span class="type">int</span> <tt class="parameter">$cmd</tt></span>   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <tt class="parameter">$args</tt></span>  ] )</div>  <p class="para rdfs-comment">   The <b>dio_fcntl()</b> function performs the   operation specified by <i><tt class="parameter">cmd</tt></i> on the file   descriptor <i><tt class="parameter">fd</tt></i>. Some commands require   additional arguments <i><tt class="parameter">args</tt></i> to be supplied.  </p> </div> <div class="refsect1 parameters">  <h3 class="title">Parameters</h3>  <p class="para">   <dl>    <dt>     <span class="term"><i><tt class="parameter">fd</tt></i></span>     <dd>      <p class="para">       The file descriptor returned by <a href="function.dio-open.html" class="function">dio_open()</a>.      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">cmd</tt></i></span>     <dd>      <p class="para">       Can be one of the following operations:       <ul class="itemizedlist">        <li class="listitem">         <p class="para">          <b><tt>F_SETLK</tt></b> - Lock is set or cleared. If the lock          is held by someone else <b>dio_fcntl()</b> returns          -1.         </p>        </li>        <li class="listitem">         <p class="para">          <b><tt>F_SETLKW</tt></b> - like <b><tt>F_SETLK</tt></b>,          but in case the lock is held by someone else,           <b>dio_fcntl()</b> waits until the lock is released.         </p>        </li>        <li class="listitem">         <p class="para">          <b><tt>F_GETLK</tt></b> - <b>dio_fcntl()</b>           returns an associative array (as described above) if someone else          prevents lock. If there is no obstruction key &quot;type&quot; will set          to <b><tt>F_UNLCK</tt></b>.         </p>        </li>        <li class="listitem">         <p class="para">          <b><tt>F_DUPFD</tt></b> - finds the lowest numbered available          file descriptor greater than or equal to <i><tt class="parameter">args</tt></i>          and returns them.         </p>        </li>        <li class="listitem">         <p class="para">          <b><tt>F_SETFL</tt></b> - Sets the file descriptors flags to           the value specified by <i><tt class="parameter">args</tt></i>, which can be          <b><tt>O_APPEND</tt></b>, <b><tt>O_NONBLOCK</tt></b> or           <b><tt>O_ASYNC</tt></b>. To use <b><tt>O_ASYNC</tt></b>           you will need to use the <a href="ref.pcntl.html" class="link">PCNTL</a>           extension.         </p>        </li>       </ul>      </p>     </dd>    </dt>    <dt>     <span class="term"><i><tt class="parameter">args</tt></i></span>     <dd>      <p class="para">       <i><tt class="parameter">args</tt></i> is an associative array, when       <i><tt class="parameter">cmd</tt></i> is <b><tt>F_SETLK</tt></b> or       <b><tt>F_SETLLW</tt></b>, with the following keys:       <ul class="itemizedlist">        <li class="listitem">         <p class="para">          &quot;start&quot; - offset where lock begins         </p>        </li>        <li class="listitem">         <p class="para">          &quot;length&quot; - size of locked area. zero means to end of file         </p>        </li>        <li class="listitem">         <p class="para">          &quot;wenth&quot; - Where l_start is relative to: can be           <b><tt>SEEK_SET</tt></b>,          <b><tt>SEEK_END</tt></b> and <b><tt>SEEK_CUR</tt></b>         </p>        </li>        <li class="listitem">         <p class="para">          &quot;type&quot; - type of lock: can be <b><tt>F_RDLCK</tt></b> (read          lock), <b><tt>F_WRLCK</tt></b> (write lock) or           <b><tt>F_UNLCK</tt></b> (unlock)         </p>        </li>       </ul>      </p>     </dd>    </dt>   </dl>  </p> </div> <div class="refsect1 returnvalues">  <h3 class="title">Return Values</h3>  <p class="para">   Returns the result of the C call.  </p> </div> <div class="refsect1 examples">  <h3 class="title">Examples</h3>  <p class="para">   <div class="example">    <p><b>Example #1 Setting and clearing a lock</b></p>    <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br />$fd&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">dio_open</span><span style="color: #007700">(</span><span style="color: #DD0000">'/dev/ttyS0'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">O_RDWR</span><span style="color: #007700">);<br /><br />if&nbsp;(</span><span style="color: #0000BB">dio_fcntl</span><span style="color: #007700">(</span><span style="color: #0000BB">$fd</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">F_SETLK</span><span style="color: #007700">,&nbsp;Array(</span><span style="color: #DD0000">"type"</span><span style="color: #007700">=&gt;</span><span style="color: #0000BB">F_WRLCK</span><span style="color: #007700">))&nbsp;==&nbsp;-</span><span style="color: #0000BB">1</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;the&nbsp;file&nbsp;descriptor&nbsp;appears&nbsp;locked<br />&nbsp;&nbsp;&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"The&nbsp;lock&nbsp;can&nbsp;not&nbsp;be&nbsp;cleared.&nbsp;It&nbsp;is&nbsp;held&nbsp;by&nbsp;someone&nbsp;else."</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"Lock&nbsp;succesfully&nbsp;set/cleared"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">dio_close</span><span style="color: #007700">(</span><span style="color: #0000BB">$fd</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>    </div>   </div>  </p> </div> <div class="refsect1 notes">  <h3 class="title">Notes</h3>  <blockquote><p><b class="note">Note</b>: <span class="simpara">This function is notimplemented on Windows platforms.</span></p></blockquote> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.dio-close.html">dio_close</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.dio-open.html">dio_open</a></div> <div class="up"><a href="ref.dio.html">Direct IO Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?