大网数据广告活动
PHP 语言与运行手册

eio_readdir · Reads through a whole directory

· 52CE 我爱测

eio_readdir — Reads through a whole directory

eio_readdir

(PECL eio >= 0.0.1dev)

eio_readdir — Reads through a whole directory

说明

function eio_readdir(
    string $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

请求的优先级:EIO_PRI_DEFAULT,EIO_PRI_MIN,EIO_PRI_MAX 或 null。如果是 null,pri 将设为 EIO_PRI_DEFAULT。

callback

callback 函数在请求完成时被调用。其应匹配一下原型:

void callback(mixed $data, int $result[, resource $req]);
data

传递给请求的用户数据。

result

针对请求的结果的值。通常是相应的系统调用返回的值。

req

可选的请求资源,可被 eio_get_last_error() 之类的函数使用。

data

Arbitrary variable passed to callback.

返回值

eio_readdir() returns request resource on success, 或者在失败时返回 false. Sets result argument of callback function according to flags:

EIO_READDIR_DENTS (int)

eio_readdir() flag. If specified, the result argument of the callback becomes an array with the following keys: '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)

When this flag is specified, the names will be returned in an order where likely directories come first, in optimal stat order.

EIO_READDIR_STAT_ORDER (int)

When this flag is specified, then the names will be returned in an order suitable for 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)

Unknown node type(very common). Further stat() needed.

EIO_DT_FIFO (int)

FIFO node type

EIO_DT_CHR (int)

Node type

EIO_DT_MPC (int)

Multiplexed char device (v7+coherent) node type

EIO_DT_DIR (int)

Directory node type

EIO_DT_NAM (int)

Xenix special named file node type

EIO_DT_BLK (int)

Node type

EIO_DT_MPB (int)

Multiplexed block device (v7+coherent)

EIO_DT_REG (int)

Node type

EIO_DT_NWK (int)

EIO_DT_CMP (int)

HP-UX network special node type

EIO_DT_LNK (int)

Link node type

EIO_DT_SOCK (int)

Socket node type

EIO_DT_DOOR (int)

Solaris door node type

EIO_DT_WHT (int)

Node type

EIO_DT_MAX (int)

Highest node type value

示例

示例 #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();
?>

以上示例的输出类似于:

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)
    }
  }
}

来源:PHP Documentation Group · 作者与贡献记录 · CC BY 3.0。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
PHP Documentation Group
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。