public function __construct($handle, $poolName) { $this->_ioctx = \rados_ioctx_create($handle, $poolName); }
<?php $rados = rados_create(); rados_conf_read_file($rados, "/etc/ceph/ceph.conf"); rados_connect($rados); $io = rados_ioctx_create($rados, "rbd"); var_dump(rados_ioctx_pool_stat($io)); rados_ioctx_destroy($io); rados_shutdown($rados);
<?php $poolname = "phprados"; $rados = rados_create(); rados_conf_read_file($rados, '/etc/ceph/ceph.conf'); rados_connect($rados); rados_pool_create($rados, $poolname); $io = rados_ioctx_create($rados, $poolname); for ($i = 0; $i < 100; $i++) { $objname = md5(rand(0, 1000)); rados_write_full($io, $objname, md5(rand(0, 100000))); echo "Created object " . $objname . "\n"; } /* List all objects */ print_r(rados_objects_list($io)); rados_ioctx_destroy($io); rados_shutdown($rados);
/** * @depends testRadosCreatePool */ public function testRadosCreateIoCTX($cluster) { $ioctx = rados_ioctx_create($cluster, getenv('pool')); $this->assertNotNull($ioctx); return $ioctx; }
/** * @param string $path * @param string $mode * @param int $options * @param string $opened_path * @return bool * @throws IOException */ public function stream_open($path, $mode, $options, &$opened_path) { $ret = $this->rados = \rados_create(); if (!$ret) { throw new IOException('Could not create rados resource'); } $configPath = '/etc/ceph/ceph.conf'; $ret = \rados_conf_read_file($this->rados, $configPath); if (!$ret) { throw new IOException("Could not read config from {$configPath}"); } $ret = \rados_connect($this->rados); if (!$ret) { throw new IOException('Could not connect to rados'); } $id = \rados_pool_lookup($this->rados, $this->pool); //TODO make autocreation configurable if ($id < 0) { $ret = \rados_pool_create($this->rados, $this->pool); if ($ret < 0) { throw new IOException("Could not create pool '{$this->pool}'"); } } $this->ioctx = \rados_ioctx_create($this->rados, $this->pool); if (!$this->ioctx) { throw new IOException("Could not create io context before reading object {$path}"); } $oid = $this->path2oid($path); $this->stat = \rados_stat($this->ioctx, $oid); switch ($mode[0]) { case 'r': if (!$this->stat) { return false; } $this->writable = isset($mode[1]) && $mode[1] == '+'; break; case 'a': if ($this->stat && $this->stat['psize']) { $this->pos = $this->stat['psize']; } break; case 'x': if (!$this->stat) { return false; } break; case 'w': case 'c': if (!$this->stat) { $this->stat = ['psize' => 0, 'oid' => $oid]; } break; default: return false; } return true; }
<?php $rados = rados_create(); rados_conf_read_file($rados, "/etc/ceph/ceph.conf"); rados_connect($rados); $io = rados_ioctx_create($rados, "phprados"); rados_write_full($io, "passwd", file_get_contents("/etc/passwd")); rados_setxattr($io, "passwd", "aap", "attr1"); rados_setxattr($io, "passwd", "noot", "attr2"); rados_setxattr($io, "passwd", "mies", "attr3"); var_dump(rados_getxattrs($io, "passwd")); rados_ioctx_destroy($io); rados_shutdown($rados);