/* Is called when the group requests are done */ function my_grp_done($data, $result) { global $temp_filename; var_dump($result == 0); @unlink($temp_filename); }
/* Is called when eio_open() done */ function my_grp_file_opened_callback($data, $result) { global $my_file_fd, $grp;
$my_file_fd = $result;
var_dump($result > 0);
// Create eio_read() request and add it to the group $req = eio_read($my_file_fd, 4, 0, EIO_PRI_DEFAULT, "my_grp_file_read_callback"); eio_grp_add($grp, $req); }
/* Is called when eio_read() done */ function my_grp_file_read_callback($data, $result) { global $my_file_fd, $grp;
var_dump($result);
// Create eio_close() request and add it to the group $req = eio_close($my_file_fd); eio_grp_add($grp, $req); }
$grp = eio_grp("my_grp_done", "my_grp_data");
// Create eio_open() request and add it to the group $req = eio_open($temp_filename, EIO_O_RDWR | EIO_O_APPEND , NULL, EIO_PRI_DEFAULT, "my_grp_file_opened_callback", NULL); eio_grp_add($grp, $req); var_dump($grp);
eio_event_loop(); ?>
Результатом выполнения данного примера
будет что-то подобное:
resource(6) of type (EIO Group Descriptor)
bool(true)
string(4) "some"
bool(true)
Пример #5 Using eio with libevent
<?php function my_eio_poll($fd, $events, $arg) { /* Some libevent regulation might go here .. */ if (eio_nreqs()) { eio_poll(); } /* .. and here */ }
function my_nop_cb($d, $r) { var_dump($r); var_dump($d); }
$base = event_base_new(); $event = event_new();
$fd = eio_get_event_stream(); var_dump($fd);
eio_nop(EIO_PRI_DEFAULT, "my_nop_cb", "nop data"); eio_mkdir("/tmp/abc-eio-temp", 0750, EIO_PRI_DEFAULT, "my_nop_cb", "nop data"); /* some other eio_* calls here ... */