Ejemplo n.º 1
0
<?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();
Ejemplo n.º 2
0
<?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();
Ejemplo n.º 3
0
 public function open($file_path, $flag, $callback)
 {
     if (isset($this->fileFlags[$flag])) {
         uv_fs_open($this->getEventLoop(), $file_path, $this->fileFlags[$flag], 0, $callback);
     }
 }
Ejemplo n.º 4
0
 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();
 }
Ejemplo n.º 5
0
<?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();
Ejemplo n.º 6
0
<?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();
Ejemplo n.º 7
0
 /**
  * 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;
 }
Ejemplo n.º 8
0
<?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();
Ejemplo n.º 9
0
<?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();