public function test_readfile_eio() { $time_start = microtime(true); echo "reading file is started....<br/>"; $file_open_cb = function ($data, $result) { eio_read($result, 10485760, 0, EIO_PRI_DEFAULT, function ($data, $result) { echo str_word_count($result) . "<br/>"; eio_close($data); }, $result); }; $filename = './assets/data/access.log'; eio_open($filename, EIO_O_RDWR, NULL, EIO_PRI_DEFAULT, $file_open_cb, $filename); $filename = './assets/data/error.log'; eio_open($filename, EIO_O_RDWR, NULL, EIO_PRI_DEFAULT, $file_open_cb, $filename); echo "reading file is finish....<br/>"; eio_event_loop(); $time_end = microtime(true); $time = $time_end - $time_start; echo "Execution time: {$time} seconds<br/>"; }
private function onPutWrite($fhAndPromisor, $result, $req) { list($fh, $promisor) = $fhAndPromisor; \eio_close($fh); $priority = \EIO_PRI_DEFAULT; \eio_close($fh, $priority, $this->callableDelReq); if ($result === -1) { $promisor->fail(new \RuntimeException(\eio_get_last_error($req))); } else { $promisor->succeed($result); } }
/** * Close the file * @return resource|false */ public function close() { if ($this->closed) { return false; } $this->closed = true; if ($this->fdCacheKey !== null) { FileSystem::$fdCache->invalidate($this->fdCacheKey); } if ($this->fd === null) { return false; } if (!FileSystem::$supported) { fclose($this->fd); return false; } $r = eio_close($this->fd, EIO_PRI_MAX); $this->fd = null; return $r; }
/** * @coroutine * * @param string $path * * @return \Generator * * @resolve int */ public function copy(string $path) : \Generator { $delayed = new Delayed(); \eio_open($path, \EIO_O_WRONLY | \EIO_O_CREAT | \EIO_O_TRUNC, 0644, null, function (Delayed $delayed, $handle, $req) { if (-1 === $handle) { $delayed->reject(new FileException(sprintf('Opening the file failed: %s.', \eio_get_last_error($req)))); } else { $delayed->resolve($handle); } }, $delayed); $this->poll->listen(); try { $handle = (yield $delayed); } finally { $this->poll->done(); } $delayed = new Delayed(); \eio_sendfile($handle, $this->handle, 0, $this->size, null, function (Delayed $delayed, $result, $req) { if (-1 === $result) { $delayed->reject(new FileException(sprintf('Copying the file failed: %s.', \eio_get_last_error($req)))); } else { $delayed->resolve(true); } }, $delayed); $this->poll->listen(); try { (yield $delayed); } finally { $this->poll->done(); \eio_close($handle); } return $this->size; }
/** * {@inheritdoc} */ public function close() { \call_user_func($this->incrementor, 1); $promisor = new Deferred(); \eio_close($this->fh, $priority = null, [$this, "onClose"], $promisor); return $promisor->promise(); }
public function closeFd() { if ($this->fdCacheKey !== null) { FS::$fdCache->invalidate($this->fdCacheKey); } if ($this->fd === null) { return; } if (FS::$supported) { $r = eio_close($this->fd); $this->fd = null; return $r; } fclose($this->fd); }