Install the Aerospike client
The two essential components of the PHP client are a robust PHP client written in Rust, and a connection manager written in Go. The connection manager daemon handles all requests and responses between the PHP processes and the Aerospike server.
Prerequisites
- Aerospike database
- PHP 8.1 or later
- PHPUnit v10
- Rustc >= v1.74
- Go Toolchain
- Protobuf Compiler
- ext-php-rs v0.12.0
- git
Building and installing the PHP client
Set up dependencies
Install PHP:
sudo apt-get install php
sudo apt-get install php-devInstall Rust:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
. "$HOME/.cargo/env"Install
gcc
toolchain and linkers:sudo apt-get install build-essential
Install
clang
:sudo apt-get install clang
export LIBCLANG_PATH="/usr/lib/llvm-10/lib/"Install Go:
Visit the Go download page and follow the installation instructions for your platform.
Install Go helpers:
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
sudo apt-get install -y protobuf-compiler
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
Set up the PHP client and connection manager
Verify that your Aerospike server is running and accessible.
Clone the aerospike/php-client repository:
git clone https://github.com/aerospike/php-client.git
Navigate to the
php-client/aerospike-connection-manager
directory.cd php-client/aerospike-connection-manager
Run the Makefile:
sudo make
Navigate back up to the
php-client
directory.cd ..
Run the Makefile:
To build and install
php-client
in the default path:sudo make
To build and install
php-client
manually:cd php-client
cargo clean && cargo build --releaseThis generates a
.so
file for Ubuntu/RHEL/CentOS and.dylib
for macOS in/target/release
in the same directory. You can then manually add the extension to your PHP setup.Copy the file from
target/release/libaerospike.[EXTENSION]
(.EXTENSION = .so for Linux and .dylib for Mac and Windows) to the PHP extension directory path.Add
extension=libaerospike.[EXTENSION]
to yourphp.ini
file.Run
phpunit tests/
to test the setup and build.noteThe Aerospike Database must be running for the tests to run successfully.
See Connecting for more information about configuring the connection manager.
Running your PHP Project
Configure a client policy in the file
php-client/daemon/asld.toml
before starting the Aerospike Connection Manager.In the
asld.toml
file, for each[cluster]
replace the placeholder values with the accessible address of your Aerospike server.Single-seed node:
host = "127.0.0.1:3000"
Multiple-seed node:
host = "1.1.1.1:3001,2.2.2.2:3002,3.3.3.3"
After configuring the
asld.toml
file, start the Aerospike Connection Manager to create a socket. The socket path can be modified in theasld.toml
file.The Aerospike server must be running. If the Aerospike server has security enabled, specify the username and password in the
asld.toml
file.Import the Aerospike namespace to your PHP script.
namespace Aerospike;
To connect to the Aerospike connection manager, add the following to your script:
<?php
namespace Aerospike;
$socket = "/tmp/asld_grpc.sock";
try{
$client = Client::connect($socket);
echo "* Connected to the local daemon: $client->socket \n";
}catch(AerospikeException $e){
echo "Failed connecting to Aerospike Server with Exception: ".$e;
}Run the script. If there are no errors, you have successfully connected to the Aerospike server.
noteIf the connection manager daemon crashes, you must manually delete the file
/tmp/asld_grpc.sock
.sudo rm -r /tmp/asld_grpc.soc
Configuring policies (read, write, batch and info): you can set these policies via getters and setters in the PHP code. On creating an object of that policy class, the default values are initialized for that policy. For example:
// Instantiate the WritePolicy object
$writePolicy = new WritePolicy();
$writePolicy->setRecordExistsAction(RecordExistsAction::Update);
$writePolicy->setGenerationPolicy(GenerationPolicy::ExpectGenEqual);
$writePolicy->setExpiration(Expiration::seconds(3600)); // Expiring in 1 hour
$writePolicy->setMaxRetries(3);
$writePolicy->setSocketTimeout(5000);
Server documentation
Bug reporting
If you find bugs, create an issue on GitHub.