PHPackages                             aerospike/aerospike-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. aerospike/aerospike-php

ActiveLibrary[Database &amp; ORM](/categories/database)

aerospike/aerospike-php
=======================

Aerospike PHP Extension Pre-Alpha

v1.4.0(9mo ago)1614.3k—7.3%8[12 issues](https://github.com/aerospike/php-client/issues)[2 PRs](https://github.com/aerospike/php-client/pulls)Apache-2.0RustPHP &gt;=8.1CI passing

Since Sep 15Pushed 7mo ago42 watchersCompare

[ Source](https://github.com/aerospike/php-client)[ Packagist](https://packagist.org/packages/aerospike/aerospike-php)[ RSS](/packages/aerospike-aerospike-php/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (1)Versions (36)Used By (0)

[![PHP version](https://camo.githubusercontent.com/183804d09fec16ca7b6209b007250b7d8db1b915042feb093a9f20e6e1f25359/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230382e312d3838393242462e737667)](https://github.com/aerospike/php-client)

Aerospike PHP 8 Client (v1.4.0)
===============================

[](#aerospike-php-8-client-v140)

An [Aerospike](https://www.aerospike.com/) client library for PHP 8

PHP-Client Introduction
-----------------------

[](#php-client-introduction)

This is the documentation for the Aerospike `PHP-Client`. The `PHP-Client` comprises of two essential components:

- the client itself, written in Rust as a PHP extension
- the connection manager (the "Aerospike Connection Manager" or "ACM") written in Go which serves as a shared resource among PHP processes. The ACM efficiently handles all requests and responses between the PHP processes and the Aerospike server, and can be configured to run as a daemonized service.

Dependencies
------------

[](#dependencies)

***NOTE:*** Any missing dependencies will be installed by the installation script

- PHP (v8.1-8.4)
- Cargo (Rust package manager)
- Aerospike server
- Linux or MacOS (Darwin)
- PHPUnit
- rustc (Rust compiler) &gt;= v1.74
- Go Toolchain [Go Toolchains - The Go Programming Language](https://go.dev/doc/toolchain)
- Protobuf Compiler [protoc-gen-go command - google.golang.org/protobuf/cmd/protoc-gen-go - Go Packages](https://pkg.go.dev/google.golang.org/protobuf/cmd/protoc-gen-go)
- ext-php-rs (PHP extension) v0.13.1 [github repository link](https://github.com/davidcole1340/ext-php-rs/tree/master)

Build &amp; Installation
------------------------

[](#build--installation)

There are 2 ways to build and install the `PHP-Client`:

1. direct script download and execution (also clones the repo for you)
2. manually clone the repo first and then run script from there

The install script builds both the `PHP-Client` and the ACM, as well as installing all of the dependencies.

Automatic Method: Direct download and execution of installation script:
-----------------------------------------------------------------------

[](#automatic-method-direct-download-and-execution-of-installation-script)

The installation script will clone the repo into a subfolder so execute this command directly above where you want the repo to go

For MacOS (Darwin):

```
curl -O https://raw.githubusercontent.com/aerospike/php-client/refs/heads/main/build/install_as_php_client_mac.zsh; chmod +x install_as_php_client_mac.zsh; ./install_as_php_client_mac.zsh
```

***NOTE***: the default MacOS installation is an all user-local installation, requiring no root or sudo access

For Linux:

```
curl -O https://raw.githubusercontent.com/aerospike/php-client/refs/heads/main/build/install_as_php_client_linux.sh; chmod +x install_as_php_client_linux.sh; sudo ./install_as_php_client_linux.sh
```

### Manual method: repo clone followed by execution of the installation script:

[](#manual-method-repo-clone-followed-by-execution-of-the-installation-script)

1. Clone the repo
2. Run the installation script for your system:

    for MacOS (darwin):

    ```
    . ./php-client/build/install_as_php_client_mac.zsh
    ```

    or for linux:

    ```
    sudo ./php-client/build/install_as_php_client_linux.sh
    ```

***NOTE***: the default linux installation contains system-wide installations and will require root / sudo access

After the installation script completes, re-source your shell env config files to make sure your `PATH` is updated. Eg, on MacOS:

```
. ~/.zshrc
```

If you encounter errors during installation, you can try running the install script again as the install scripts attempt to be idempotent. As a last resort, the script commands can be run manually one-by-one as needed.

### Configuring the Aerospike Connection Manager:

[](#configuring-the-aerospike-connection-manager)

***NOTE:*** Please view the README.md in the [`php-client/aerospike-connection-manager`](./aerospike-connection-manager/README.md) directory for more information about the setting up the aerospike-connection-manager and configuring the client policy.

***NOTE:*** You should have an [Aerospike server](https://aerospike.com/download/) up and running to test against.

### Manual Build and Install of the PHP-Client (optional)

[](#manual-build-and-install-of-the-php-client-optional)

In case the installation script fails to build the `PHP-Client`, or if you just want to run specific build commands, you may do so manually:

- To manually build and install the `PHP-Client` in the default paths run the makefile

    Note: sudo is only needed when running a system-wide php installation, which is not the default install for MacOS (although it could be)

    ```
     cd php-client
     make
    ```
- To build and install the `PHP-Client` in manually, run the following commands:

    ```
     cd php-client
     cargo clean && cargo build --release
    ```

- Once the build is successful, 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 your `php.ini` file.
- Run `phpunit tests/` to ensure the setup and build were successful.

***NOTE***: The Aerospike server must be running for the tests to run successfully.

### Running your PHP Project

[](#running-your-php-project)

- Before running your project PHP scripts, the following must be running:

    - An Aerospike Connection Manager (ACM)
    - An Aerospike Server that the ACM can connect to
- Once the build is successful and all the pre-requisites are met, import the Aerospike namespace to your PHP script:

    ```
    namespace Aerospike;
    ```
- To connect to the Aerospike server via the ACM add:

    ```
    $socket = "/tmp/asld_grpc.sock";
    $client = Client::connect($socket);
    ```
- Run the php script If there are no Errors then you have successfully connected to the Aerospike DB.

    ***NOTE:*** If the connection manager daemon crashes, you will have to manually remove the file `/tmp/asld_grpc.sock` from its path.

    ```
    sudo rm -r /tmp/asld_grpc.sock
    ```
- Policy Configuration (Read, Write, Batch and Info) - These policies can be set via getters and setter in the php code. On creation of an object of that policy class (eg, WritePolicy), the default values are initialized for that policy &amp; can be overidden with associated setters. 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);
    ```

Documentation
-------------

[](#documentation)

- Reference Documentation can be found \[here\] ()
- Aerospike Documentation can be found [here](https://aerospike.com/docs/)

Issues
------

[](#issues)

If there are any bugs, feature requests or feedback -&gt; please create an issue on [GitHub](https://github.com/aerospike/php-client/issues). Issues will be regularly reviewed by the Aerospike Client Engineering Team.

Usage
-----

[](#usage)

**The following is a very simple example of CRUD operations in an Aerospike database.**

```
