Download the PHP package aternos/rados-ffi without Composer
On this page you can find all versions of the php package aternos/rados-ffi. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download aternos/rados-ffi
More information about aternos/rados-ffi
Files in aternos/rados-ffi
Package rados-ffi
Short Description An object oriented PHP library for using librados with FFI
License LGPL-2.1-only
Informations about the package rados-ffi
php-rados-ffi
An object oriented PHP library for using librados with FFI.
Requirements
- Linux
- PHP 8.1 or later
- php-ffi
- librados
Installation
Why not phprados?
The phprados extension is a native PHP extension that provides bindings to librados. Unfortunately, it has been largely unmaintained for the past few years. While it does compile for the latest version of PHP, many of the included rados functions do not work as intended and can cause crashes. Additionally, phprados only adds bindings for a small subset of the librados API.
php-rados-ffi provides a modern, object-oriented, and complete interface to librados using PHP's FFI system. Through FFI, PHP can load shared libraries like librados and call their functions directly. This allows using librados without a native PHP extension, making it easier to install and safer to update.
Usage
Before the library can be used, the librados shared library must be loaded.
This can be done using the initialize()
method of the Rados
class.
Preloading
To preload librados, ensure that FFI preloading is enabled and add the following line to your opcache.preload
file:
Rados can then be initialized by calling initializePreloaded()
instead of initialize()
.
Cluster
The Cluster
instance,
which is used to connect to a Ceph cluster.
Once connected, a Cluster
object can be used to perform operations and
request information about the cluster.
It is, for example, possible to ping monitors, request the cluster's ID, or list pools.
Pool
IOContext
.
IOContext
IOContext
objects are used to perform operations on a pool.
It can, for example, be used to iterate over objects in the pool, or to get a specific object.
RadosObject
A RadosObject
represents an object in a Ceph pool,
and can be used to read and write data or modify attributes.
Async operations and completions
Many IO operations can be performed asynchronously. Asynchronous operations return
a ResultCompletion
object, which can be used to track the status of
the operation and to wait for its completion.
To check the status of a completion, the isComplete()
method can be used.
It is also possible to block until the operation is complete using the waitForComplete()
method.
Completions can be canceled by calling the cancel()
method.
The result of the operation can be obtained using the getResult()
method. The type
of the result depends on the operation that was performed.
If the operation failed, the getResult()
method will throw an exception.
Likewise, an exception will be thrown if the operation was not completed yet.
To avoid this, waitAndGetResult()
can be used to block until the operation
is complete and to get the result.
Object operations
Object operations allow
performing multiple tasks on an object atomically. Write and read operations can be created by calling
$rados->createWriteOperation()
and $rados->createReadOperation()
respectively.
Some tasks, especially in read operations, will return data. This data can be accessed by
calling getResult()
on the task object after the operation has been completed.
If the task failed, getResult()
may throw an exception.
If a single task in an operation fails, the entire operation will fail.
This can be avoided by adding the OperationTaskFlag::FailOK
flag to tasks that are allowed to fail.
Operations can also be executed asynchronously, using the operateAsync()
method.
Available tasks
Common
AssertExistsTask
AssertVersionTask
CompareExtTask
CompareXAttributeTask
OMapCompareTask
Read
ChecksumTask
ExecuteTask
(with output data)GetXAttributesTask
OMapGetByKeysTask
OMapGetKeysTask
OMapGetTask
ReadTask
StatTask
Write
AppendTask
CreateObjectTask
ExecuteTask
(without output data)OMapClearTask
OMapRemoveKeyRangeTask
OMapRemoveKeysTask
OMapSetTask
RemoveTask
RemoveXAttributeTask
SetAllocHintTask
SetXAttributeTask
TruncateTask
WriteFullTask
WriteSameTask
WriteTask
ZeroTask
Exceptions and error handling
If a Rados operation fails, it will throw a RadosException
.
The error code returned from librados can be obtained using the getCode()
method.
To check whether an error has a specific error code, the is()
method can be used.
Available Rados features
This library aims to implement the full librados API. There are, however, some features can't be implemented due to limitations in PHP's FFI system.
Not planned
- Callback functions for completions
- Watch/Notify
- Log callbacks
PHP callback functions can be passed to C functions using FFI, but they can only be called (more or less) safely from the main thread. Since both completions and watches can be called from any thread, using PHP callback functions is not feasible.
Implemented, but not really supported
Some librados features are poorly documented to a point where I do not understand what they are supposed to do. These features have bindings in this library, but I can't guarantee that they work as intended. Currently, this includes:
- Self-managed snapshots
- rados_(un)set_pool_full_try
How to not segfault
The library uses FFI to call into the librados shared library.
To avoid crashes from incorrect usage of librados, only call methods and constructors
that are public
and not marked as @internal
in the source code.
Methods marked as @internal
are not part of the public API and should not be called directly.
License
php-rados-ffi - PHP library for Ceph RADOS using FFI
Copyright (C) 2024 Aternos GmbH
This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1, as published by the Free Software Foundation. See file LICENSE.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Documentation comments in this library are derived from documentation comments from librados. The file includes/librados.h is generated from librados.h, which is part of Ceph. Source code for Ceph is available at https://github.com/ceph/ceph
Ceph - scalable distributed file system
Copyright (C) 2004-2012 Sage Weil [email protected]
This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License version 2.1, as published by the Free Software Foundation. See file LICENSE.