(PECL eio >= 0.0.1dev)
eio_readdir — Reads through a whole directory
$path
, int $flags
, int $pri
, callable $callback
[, string $data
= NULL
] ) : resource
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.
path
Directory path.
flags
Combination of EIO_READDIR_* constants.
pri
Priorytet zapytania: EIO_PRI_DEFAULT
, EIO_PRI_MIN
, EIO_PRI_MAX
, lub NULL
.
Jeśli podana zostanie wartość NULL
, parametr pri
jest wewnętrznie ustawiany na
EIO_PRI_DEFAULT
.
callback
Funkcja callback
jest wywoływana po zakończeniu wywołania. Powinna ona być zgodna z następującym prototypem:
void callback(mixed $dane, int $wynik[, resource $zapytanie]);
dane
dane przekazywane do zapytania.
wynik
wartość wynikowa, zależna od zapytania; ogólnie, jest to wartość zwracana przez odpowiednie wywołanie systemowe.
zapytanie
opcjonalny zasób zapytania, który może być użyty z funkcjami takimi jak eio_get_last_error()
data
Arbitrary variable passed to callback
.
eio_readdir() returns request resource on success, or
FALSE
on error. Sets result
argument of
callback
function according to
flags
:
EIO_READDIR_DENTS
(integer)
EIO_READDIR_DIRS_FIRST
(integer)
EIO_READDIR_STAT_ORDER
(integer)
EIO_READDIR_FOUND_UNKNOWN
(integer)
Node types:
EIO_DT_UNKNOWN
(integer)
EIO_DT_FIFO
(integer)
EIO_DT_CHR
(integer)
EIO_DT_MPC
(integer)
EIO_DT_DIR
(integer)
EIO_DT_NAM
(integer)
EIO_DT_BLK
(integer)
EIO_DT_MPB
(integer)
EIO_DT_REG
(integer)
EIO_DT_NWK
(integer)
EIO_DT_CMP
(integer)
EIO_DT_LNK
(integer)
EIO_DT_SOCK
(integer)
EIO_DT_DOOR
(integer)
EIO_DT_WHT
(integer)
EIO_DT_MAX
(integer)
Przykład #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();
?>
Powyższy przykład wyświetli coś podobnego do:
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) } } }