(PECL eio >= 0.0.1dev)
eio_fstat — 取得檔案狀態
eio_fstat() 會在 callback 的 result 參數中傳回檔案狀態資訊
fd串流、Socket 資源或數值型態的檔案描述子。
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傳遞給 callback 的任意變數。
eio_busy() 在成功時會傳回請求資源,失敗時會傳回 false。
範例 #1 eio_lstat() 範例
<?php
// 建立暫存檔
$tmp_filename = dirname(__FILE__) ."/eio-file.tmp";
touch($tmp_filename);
/* 當 eio_fstat() 完成時呼叫 */
function my_res_cb($data, $result) {
// 應輸出包含 stat 資訊的陣列
var_dump($result);
if ($data['fd']) {
// 關閉暫存檔
eio_close($data['fd']);
eio_event_loop();
}
// 移除暫存檔
@unlink($data['file']);
}
/* 當 eio_open() 完成時呼叫 */
function my_open_cb($data, $result) {
// 準備回呼的資料
$d = array(
'fd' => $result,
'file'=> $data
);
// 請求 stat 資訊
eio_fstat($result, EIO_PRI_DEFAULT, "my_res_cb", $d);
// 處理請求
eio_event_loop();
}
// 開啟暫存檔
eio_open($tmp_filename, EIO_O_RDONLY, NULL, EIO_PRI_DEFAULT,
"my_open_cb", $tmp_filename);
eio_event_loop();
?>上面的範例會輸出類似以下的內容
array(12) {
["st_dev"]=>
int(2050)
["st_ino"]=>
int(2489159)
["st_mode"]=>
int(33188)
["st_nlink"]=>
int(1)
["st_uid"]=>
int(1000)
["st_gid"]=>
int(100)
["st_rdev"]=>
int(0)
["st_blksize"]=>
int(4096)
["st_blocks"]=>
int(0)
["st_atime"]=>
int(1318239506)
["st_mtime"]=>
int(1318239506)
["st_ctime"]=>
int(1318239506)
}