<?php uv_fs_open(uv_default_loop(), __FILE__, UV::O_RDONLY, 0, function ($r) { uv_fs_fstat(uv_default_loop(), $r, function ($result, $da) { var_dump($da); }); }); uv_run();
<?php uv_fs_open(uv_default_loop(), "./tmp", UV::O_WRONLY | UV::O_CREAT | UV::O_APPEND, UV::S_IRWXU | UV::S_IRUSR, function ($r) { var_dump($r); uv_fs_write(uv_default_loop(), $r, "hello", 0, function ($a) use($r) { var_dump($a); var_dump("ok"); uv_fs_fdatasync(uv_default_loop(), $r, function () { echo "fsync finished"; }); }); }); uv_run();
public function open($file_path, $flag, $callback) { if (isset($this->fileFlags[$flag])) { uv_fs_open($this->getEventLoop(), $file_path, $this->fileFlags[$flag], 0, $callback); } }
private function doFsOpen($path, $flags, $mode) { $promisor = new Deferred(); \uv_fs_open($this->loop, $path, $flags, $mode, function ($fh) use($promisor, $path) { $promisor->succeed($fh); }); return $promisor->promise(); }
<?php uv_fs_open(uv_default_loop(), __FILE__, UV::O_RDONLY, 0, function ($r) { uv_fs_read(uv_default_loop(), $r, function ($stream, $nread, $data) { if ($nread <= 0) { if ($nread < 0) { throw new Exception("read error"); } uv_fs_close(uv_default_loop(), $stream, function () { }); } else { echo $data; } }); }); uv_run();
<?php uv_fs_open(uv_default_loop(), "./tmp", UV::O_WRONLY, UV::S_IRWXU | UV::S_IRUSR, function ($r) { var_dump($r); uv_fs_ftruncate(uv_default_loop(), $r, 0, function () use($r) { uv_fs_close(uv_default_loop(), $r, function () { }); }); }); uv_run();
/** * Opens a file for reading/writing, assigning a mode to the file if was newly created. * The callback will get $this instance and a new instance of class Gplanchat\Io\Filesystem\FileInterface * on which file-related operations will be possible. * * @param string $path * @param int $flags * @param int $chmod * @param callable $callback * @return $this */ public function openMode($path, $flags, $chmod, callable $callback = null) { $self = $this; \uv_fs_open($this->getLoop()->getBackend(), $path, $flags, $chmod, function ($streamId) use($callback, $self) { if ($callback === null) { return; } $callback($self, new File($self, $streamId)); }); return $this; }
<?php uv_fs_open(uv_default_loop(), __FILE__, UV::O_RDONLY, 0, function ($read_fd) { $stdout = 0; uv_fs_sendfile(uv_default_loop(), $stdout, $read_fd, 0, 6, function ($result) { }); }); uv_run();
<?php uv_fs_open(uv_default_loop(), "/dev/tty", UV::O_RDONLY, 0, function ($r) { $tty = uv_tty_init(uv_default_loop(), $r, 1); var_dump(uv_tty_get_winsize($tty, $width, $height)); var_dump($width, $height); }); uv_run();