uTools-Manuals/docs/php/eio_readdir.html
2019-04-08 23:22:26 +08:00

610 lines
16 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>Reads through a whole directory</title>
</head>
<body class="docs"><div id="layout">
<div id="layout-content"><div id="function.eio-readdir" class="refentry">
<div class="refnamediv">
<h1 class="refname">eio_readdir</h1>
<p class="verinfo">(PECL eio &gt;= 0.0.1dev)</p><p class="refpurpose"><span class="refname">eio_readdir</span> &mdash; <span class="dc-title">Reads through a whole directory</span></p>
</div>
<div class="refsect1 description" id="refsect1-function.eio-readdir-description">
<h3 class="title">说明</h3>
<div class="methodsynopsis dc-description">
<span class="methodname"><strong>eio_readdir</strong></span>
( <span class="methodparam"><span class="type">string</span> <code class="parameter">$path</code></span>
, <span class="methodparam"><span class="type">int</span> <code class="parameter">$flags</code></span>
, <span class="methodparam"><span class="type">int</span> <code class="parameter">$pri</code></span>
, <span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>
[, <span class="methodparam"><span class="type">string</span> <code class="parameter">$data</code><span class="initializer"> = NULL</span></span>
] ) : <span class="type">resource</span></div>
<p class="para rdfs-comment">
Reads through a whole directory(via the <em>opendir</em>, <em>readdir</em> and
<em>closedir</em> system calls) and returns either the names or an array in
<code class="parameter">result</code> argument of <code class="parameter">callback</code>
function, depending on the <code class="parameter">flags</code> argument.
</p>
</div>
<div class="refsect1 parameters" id="refsect1-function.eio-readdir-parameters">
<h3 class="title">参数</h3>
<dl>
<dt>
<code class="parameter">path</code></dt>
<dd>
<p class="para">
Directory path.
</p>
</dd>
<dt>
<code class="parameter">flags</code></dt>
<dd>
<p class="para">
Combination of <em class="emphasis">EIO_READDIR_*</em> constants.
</p>
</dd>
<dt>
<code class="parameter">pri</code></dt>
<dd>
<p class="para">请求的优先级:<strong><code>EIO_PRI_DEFAULT</code></strong><strong><code>EIO_PRI_MIN</code></strong><strong><code>EIO_PRI_MAX</code></strong><strong><code>NULL</code></strong>。如果是
<strong><code>NULL</code></strong><code class="parameter">pri</code> 将设为
<strong><code>EIO_PRI_DEFAULT</code></strong>
</p>
</dd>
<dt>
<code class="parameter">callback</code></dt>
<dd>
<p class="para">
<code class="parameter">callback</code>
函数在请求完成时被调用。其应匹配一下原型:<div class="example-contents"><div class="phpcode"><pre><span style="color: #000000">
void&nbsp;callback(mixed&nbsp;$data,&nbsp;int&nbsp;$result[,&nbsp;resource&nbsp;$req]);</span>
</pre></div></div>
<dl>
<dt>
<code class="parameter">data</code></dt>
<dd>
<p class="para">传递给请求的用户数据。</p></dd>
<dt>
<code class="parameter">result</code></dt>
<dd>
<p class="para">针对请求的结果的值。通常是相应的系统调用返回的值。</p></dd>
<dt>
<code class="parameter">req</code></dt>
<dd>
<p class="para">可选的请求资源,可被 <span class="function"><a href="eio_get_last_error.html" class="function">eio_get_last_error()</a></span>
之类的函数使用。</p></dd>
</dl>
</p>
</dd>
<dt>
<code class="parameter">data</code></dt>
<dd>
<p class="para">
Arbitrary variable passed to <code class="parameter">callback</code>.
</p>
</dd>
</dl>
</div>
<div class="refsect1 returnvalues" id="refsect1-function.eio-readdir-returnvalues">
<h3 class="title">返回值</h3>
<p class="para">
<span class="function"><strong>eio_readdir()</strong></span> returns request resource on success, or
<strong><code>FALSE</code></strong> on error. Sets <code class="parameter">result</code> argument of
<code class="parameter">callback</code> function according to
<code class="parameter">flags</code>:
</p>
<p class="para">
<dl>
<dt>
<strong><code>EIO_READDIR_DENTS</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
<span class="function"><strong>eio_readdir()</strong></span> flag. If specified, the result argument of the callback
becomes an array with the following keys:
<em>&#039;names&#039;</em> - array of directory names
<em>&#039;dents&#039;</em> - array of <em>struct
eio_dirent</em>-like arrays having the following keys each:
<em>&#039;name&#039;</em> - the directory name;
<em>&#039;type&#039;</em> - one of <em class="emphasis">EIO_DT_*</em>
constants;
<em>&#039;inode&#039;</em> - the inode number, if available, otherwise
unspecified;
</span>
</dd>
<dt>
<strong><code>EIO_READDIR_DIRS_FIRST</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
When this flag is specified, the names will be returned in an order
where likely directories come first, in optimal stat order.
</span>
</dd>
<dt>
<strong><code>EIO_READDIR_STAT_ORDER</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
When this flag is specified, then the names will be returned in an order
suitable for <em>stat</em>&#039;ing each one. When planning to
<span class="function"><a href="stat.html" class="function">stat()</a></span> all files in the given directory, the
returned order will likely be
fastest.
</span>
</dd>
<dt>
<strong><code>EIO_READDIR_FOUND_UNKNOWN</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
</span>
</dd>
</dl>
</p>
<p class="para">Node types:
<dl>
<dt>
<strong><code>EIO_DT_UNKNOWN</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
Unknown node type(very common). Further <span class="function"><a href="stat.html" class="function">stat()</a></span> needed.
</span>
</dd>
<dt>
<strong><code>EIO_DT_FIFO</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
FIFO node type
</span>
</dd>
<dt>
<strong><code>EIO_DT_CHR</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
Node type
</span>
</dd>
<dt>
<strong><code>EIO_DT_MPC</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
Multiplexed char device (v7+coherent) node type
</span>
</dd>
<dt>
<strong><code>EIO_DT_DIR</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
Directory node type
</span>
</dd>
<dt>
<strong><code>EIO_DT_NAM</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
Xenix special named file node type
</span>
</dd>
<dt>
<strong><code>EIO_DT_BLK</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
Node type
</span>
</dd>
<dt>
<strong><code>EIO_DT_MPB</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
Multiplexed block device (v7+coherent)
</span>
</dd>
<dt>
<strong><code>EIO_DT_REG</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
Node type
</span>
</dd>
<dt>
<strong><code>EIO_DT_NWK</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
</span>
</dd>
<dt>
<strong><code>EIO_DT_CMP</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
HP-UX network special node type
</span>
</dd>
<dt>
<strong><code>EIO_DT_LNK</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
Link node type
</span>
</dd>
<dt>
<strong><code>EIO_DT_SOCK</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
Socket node type
</span>
</dd>
<dt>
<strong><code>EIO_DT_DOOR</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
Solaris door node type
</span>
</dd>
<dt>
<strong><code>EIO_DT_WHT</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
Node type
</span>
</dd>
<dt>
<strong><code>EIO_DT_MAX</code></strong>
(<span class="type"><a href="language.types.integer.html" class="type integer">integer</a></span>)
</dt>
<dd>
<span class="simpara">
Highest node type value
</span>
</dd>
</dl>
</p>
</div>
<div class="refsect1 examples" id="refsect1-function.eio-readdir-examples">
<h3 class="title">范例</h3>
<div class="example" id="example-4284">
<p><strong>Example #1 <span class="function"><strong>eio_readdir()</strong></span> example</strong></p>
<div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;Is&nbsp;called&nbsp;when&nbsp;eio_readdir()&nbsp;finishes&nbsp;*/<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">my_readdir_callback</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$result</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">__FUNCTION__</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"&nbsp;called\n"</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"data:&nbsp;"</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$data</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"result:&nbsp;"</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #0000BB">eio_readdir</span><span style="color: #007700">(</span><span style="color: #DD0000">"/var/spool/news"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">EIO_READDIR_STAT_ORDER&nbsp;</span><span style="color: #007700">|&nbsp;</span><span style="color: #0000BB">EIO_READDIR_DIRS_FIRST</span><span style="color: #007700">,<br />&nbsp;&nbsp;</span><span style="color: #0000BB">EIO_PRI_DEFAULT</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"my_readdir_callback"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">eio_event_loop</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
</div>
<div class="example-contents"><p>以上例程的输出类似于:</p></div>
<div class="example-contents screen">
<div class="cdata"><pre>
my_readdir_callback called
data: NULL
result: array(2) {
[&quot;names&quot;]=&gt;
array(7) {
[0]=&gt;
string(7) &quot;archive&quot;
[1]=&gt;
string(8) &quot;articles&quot;
[2]=&gt;
string(8) &quot;incoming&quot;
[3]=&gt;
string(7) &quot;innfeed&quot;
[4]=&gt;
string(8) &quot;outgoing&quot;
[5]=&gt;
string(8) &quot;overview&quot;
[6]=&gt;
string(3) &quot;tmp&quot;
}
[&quot;dents&quot;]=&gt;
array(7) {
[0]=&gt;
array(3)
{
[&quot;name&quot;]=&gt;
string(7)
&quot;archive&quot;
[&quot;type&quot;]=&gt;
int(4)
[&quot;inode&quot;]=&gt;
int(393265)
}
[1]=&gt;
array(3)
{
[&quot;name&quot;]=&gt;
string(8)
&quot;articles&quot;
[&quot;type&quot;]=&gt;
int(4)
[&quot;inode&quot;]=&gt;
int(393266)
}
[2]=&gt;
array(3)
{
[&quot;name&quot;]=&gt;
string(8)
&quot;incoming&quot;
[&quot;type&quot;]=&gt;
int(4)
[&quot;inode&quot;]=&gt;
int(393267)
}
[3]=&gt;
array(3)
{
[&quot;name&quot;]=&gt;
string(7)
&quot;innfeed&quot;
[&quot;type&quot;]=&gt;
int(4)
[&quot;inode&quot;]=&gt;
int(393269)
}
[4]=&gt;
array(3)
{
[&quot;name&quot;]=&gt;
string(8)
&quot;outgoing&quot;
[&quot;type&quot;]=&gt;
int(4)
[&quot;inode&quot;]=&gt;
int(393270)
}
[5]=&gt;
array(3)
{
[&quot;name&quot;]=&gt;
string(8)
&quot;overview&quot;
[&quot;type&quot;]=&gt;
int(4)
[&quot;inode&quot;]=&gt;
int(393271)
}
[6]=&gt;
array(3)
{
[&quot;name&quot;]=&gt;
string(3)
&quot;tmp&quot;
[&quot;type&quot;]=&gt;
int(4)
[&quot;inode&quot;]=&gt;
int(393272)
}
}
}
</pre></div>
</div>
</div>
</div>
</div></div></div></body></html>