Skip to main content

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

Building and installing the PHP client

Set up dependencies

  1. Install PHP:

    sudo apt-get install php
    sudo apt-get install php-dev
  2. Install Rust:

    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
    . "$HOME/.cargo/env"
  3. Install gcc toolchain and linkers:

    sudo apt-get install build-essential
  4. Install clang:

    sudo apt-get install clang
    export LIBCLANG_PATH="/usr/lib/llvm-10/lib/"
  5. Install Go:

    Visit the Go download page and follow the installation instructions for your platform.

  6. 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

  1. Verify that your Aerospike server is running and accessible.

  2. Clone the aerospike/php-client repository:

    git clone https://github.com/aerospike/php-client.git
  3. Navigate to the php-client/aerospike-connection-manager directory.

    cd php-client/aerospike-connection-manager
  4. Run the Makefile:

    sudo make
  5. Navigate back up to the php-client directory.

    cd ..
  6. 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 --release

    This 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.

  7. Copy the file from target/release/libaerospike.[EXTENSION] (.EXTENSION = .so for Linux and .dylib for Mac and Windows) to the PHP extension directory path.

  8. Add extension=libaerospike.[EXTENSION] to your php.ini file.

  9. Run phpunit tests/ to test the setup and build.

    note

    The 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 the asld.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.

    note

    If 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.