(PECL eio >= 0.0.1dev)
eio_readdir — Reads through a whole directory
Reads through a whole directory(via the opendir, readdir and
closedir system calls) and returns either the names or an array in
result argument of callback
function, depending on the flags argument.
pathDirectory path.
flagsCombination of EIO_READDIR_* constants.
pri請(qǐng)求的優(yōu)先級(jí):EIO_PRI_DEFAULT,EIO_PRI_MIN,EIO_PRI_MAX 或 null。如果是
null,pri 將設(shè)為
EIO_PRI_DEFAULT。
callback
callback
函數(shù)在請(qǐng)求完成時(shí)被調(diào)用。其應(yīng)匹配一下原型:
void callback(mixed $data, int $result[, resource $req]);
data傳遞給請(qǐng)求的用戶(hù)數(shù)據(jù)。
result針對(duì)請(qǐng)求的結(jié)果的值。通常是相應(yīng)的系統(tǒng)調(diào)用返回的值。
req可選的請(qǐng)求資源,可被 eio_get_last_error() 之類(lèi)的函數(shù)使用。
data
Arbitrary variable passed to callback.
eio_readdir() returns request resource on success, 或者在失敗時(shí)返回 false.
Sets result argument of
callback function according to
flags:
EIO_READDIR_DENTS
(int)
'names' - array of directory names
'dents' - array of struct
eio_dirent-like arrays having the following keys each:
'name' - the directory name;
'type' - one of EIO_DT_*
constants;
'inode' - the inode number, if available, otherwise
unspecified;
EIO_READDIR_DIRS_FIRST
(int)
EIO_READDIR_STAT_ORDER
(int)
stat'ing each one. When planning to
stat() all files in the given directory, the
returned order will likely be
fastest.
EIO_READDIR_FOUND_UNKNOWN
(int)
Node types:
EIO_DT_UNKNOWN
(int)
EIO_DT_FIFO
(int)
EIO_DT_CHR
(int)
EIO_DT_MPC
(int)
EIO_DT_DIR
(int)
EIO_DT_NAM
(int)
EIO_DT_BLK
(int)
EIO_DT_MPB
(int)
EIO_DT_REG
(int)
EIO_DT_NWK
(int)
EIO_DT_CMP
(int)
EIO_DT_LNK
(int)
EIO_DT_SOCK
(int)
EIO_DT_DOOR
(int)
EIO_DT_WHT
(int)
EIO_DT_MAX
(int)
示例 #1 eio_readdir() example
<?php
/* Is called when eio_readdir() finishes */
function my_readdir_callback($data, $result) {
echo __FUNCTION__, " called\n";
echo "data: "; var_dump($data);
echo "result: "; var_dump($result);
echo "\n";
}
eio_readdir("/var/spool/news", EIO_READDIR_STAT_ORDER | EIO_READDIR_DIRS_FIRST,
EIO_PRI_DEFAULT, "my_readdir_callback");
eio_event_loop();
?>
以上例程的輸出類(lèi)似于:
my_readdir_callback called
data: NULL
result: array(2) {
["names"]=>
array(7) {
[0]=>
string(7) "archive"
[1]=>
string(8) "articles"
[2]=>
string(8) "incoming"
[3]=>
string(7) "innfeed"
[4]=>
string(8) "outgoing"
[5]=>
string(8) "overview"
[6]=>
string(3) "tmp"
}
["dents"]=>
array(7) {
[0]=>
array(3)
{
["name"]=>
string(7)
"archive"
["type"]=>
int(4)
["inode"]=>
int(393265)
}
[1]=>
array(3)
{
["name"]=>
string(8)
"articles"
["type"]=>
int(4)
["inode"]=>
int(393266)
}
[2]=>
array(3)
{
["name"]=>
string(8)
"incoming"
["type"]=>
int(4)
["inode"]=>
int(393267)
}
[3]=>
array(3)
{
["name"]=>
string(7)
"innfeed"
["type"]=>
int(4)
["inode"]=>
int(393269)
}
[4]=>
array(3)
{
["name"]=>
string(8)
"outgoing"
["type"]=>
int(4)
["inode"]=>
int(393270)
}
[5]=>
array(3)
{
["name"]=>
string(8)
"overview"
["type"]=>
int(4)
["inode"]=>
int(393271)
}
[6]=>
array(3)
{
["name"]=>
string(3)
"tmp"
["type"]=>
int(4)
["inode"]=>
int(393272)
}
}
}