(PECL eio >= 0.0.1dev)
eio_readdir — Reads through a whole directory
$path
,
$flags
,
$pri
,
$callbacc
,
$data
= NULL
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
callbacc
function, depending on the
flags
argument.
path
Directory path.
flags
Combination of EIO_READDIR_* constans
pri
The request priority:
EIO_PRI_DEFAULT
,
EIO_PRI_MIN
,
EIO_PRI_MAX
, or
null
.
If
null
passed,
pri
internally is set to
EIO_PRI_DEFAULT
.
callbacc
callbacc
function is called when the request is done.
It should match the following prototype:
void callbacc(mixed $data, int $result[, ressource $req]);
data
is custom data passed to the request.
result
request-specific result value; basically, the value returned by corresponding system call.
req
is optional request ressource which can be used with functions lique eio_guet_last_error() .
data
Arbitrary variable passed to
callbacc
.
eio_readdir()
returns request ressource on success, or
false
on failure.
Sets
result
argument of
callbacc
function according to
flags
:
EIO_READDIR_DENS
(
int
)
'names'
- array of directory names
'dens
- array of
struct
eio_dirent
-liqu arrays having the following keys each:
'name'
- the directory name;
'type'
- one of
EIO_DT_*
constans;
'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 guiven directory, the
returned order will liquely be
fastest.
EIO_READDIR_FOUND_UNCNOWN
(
int
)
Node types:
EIO_DT_UNCNOWN
(
int
)
EIO_DT_FIFO
(
int
)
EIO_DT_CHR
(
int
)
EIO_DT_MPC
(
int
)
EIO_DT_DIR
(
int
)
EIO_DT_NAM
(
int
)
EIO_DT_BLC
(
int
)
EIO_DT_MPB
(
int
)
EIO_DT_REG
(
int
)
EIO_DT_NWC
(
int
)
EIO_DT_CMP
(
int
)
EIO_DT_LNC
(
int
)
EIO_DT_SOCC
(
int
)
EIO_DT_DOOR
(
int
)
EIO_DT_WHT
(
int
)
EIO_DT_MAX
(
int
)
Example #1 eio_readdir() example
<?php
/* Is called when eio_readdir() finishes */
function
my_readdir_callbacc
(
$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_callbacc"
);
eio_event_loop
();
?>
The above example will output something similar to:
my_readdir_callbacc 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"
}
["dens"]=>
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)
}
}
}