Skip to content

Commit

Permalink
pre-alpha release for the aerospike php client (#2)
Browse files Browse the repository at this point in the history
Initial pre-alpha features.
---------

Co-authored-by: Khosrow Afroozeh <[email protected]>
  • Loading branch information
vmsachin and khaf authored Sep 15, 2023
1 parent 41753f4 commit a7a99dd
Show file tree
Hide file tree
Showing 15 changed files with 5,205 additions and 1 deletion.
Binary file added .DS_Store
Binary file not shown.
51 changes: 51 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Build and Test

on:
push:
branches:
- php-rs

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install Rust
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
- name: Install PHP Build Dependencies
run: |
sudo apt-get update
sudo apt-get install -y autoconf2.13 bison2.7 libbison-dev libcurl4-openssl-dev libssl-dev libxml2-dev libjpeg-dev libpng-dev libicu-dev libmcrypt-dev libreadline-dev libfreetype6-dev libzip-dev
- name: Clone the php-src repository
run: |
git clone https://github.com/php/php-src.git
cd php-src
git checkout PHP-8.1
- name: Build and Install PHP
run: |
cd php-src
./buildconf
PREFIX="${HOME}/build/php"
./configure --prefix="${PREFIX}" \
--enable-debug \
--disable-all --disable-cgi
make -j "$(nproc)"
make install
echo "${PREFIX}/bin" >> $GITHUB_PATH
- name: Verify Installed PHP Version
run: |
${HOME}/build/php/bin/php -v
- name: Run 'make' command
run: |
make
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
*.todo
aerospike-rust-client.sublime-project
aerospike-rust-client.sublime-workspace
/log
.idea/
.DS_Store
22 changes: 22 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "aerospike"
version = "0.1.0"
edition = "2018"

[lib]
crate-type = ["cdylib"]

[dependencies]
ordered-float = { version = "3", default-features = false }
aerospike-sync = { git = "https://github.com/aerospike/aerospike-client-rust.git", branch = "php-rs", package = "aerospike-sync" }
aerospike-core = { git = "https://github.com/aerospike/aerospike-client-rust.git", branch = "php-rs", package = "aerospike-core" }
ext-php-rs = "0.10.1"
colored = "2.0.0"
hex = "0.4"
log = "0.4"
env_logger = "0.9.3"
chrono="0.4"
lazy_static = "1.1.1"

[profile.release]
strip = "debuginfo"
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Go parameters
hosts ?= ""
host ?= localhost
port ?= 3000
user ?= ""
pass ?= ""
ns ?= "test"

# Determine the operating system
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
EXTENSION := .dylib
EXT_DIR_PATH := /opt/homebrew/opt/[email protected]/pecl/20210902
PHP_INI_PATH := /opt/homebrew/etc/php/8.1/php.ini
RESTART_COMMAND := brew services restart [email protected]
else ifeq ($(UNAME_S),Linux)
EXTENSION := .so
EXT_DIR_PATH := /usr/lib/php/20210902/
PHP_INI_PATH := /etc/php/8.1/cli/php.ini
RESTART_COMMAND := sudo systemctl restart php8.1-fpm && sudo systemctl restart apache2
else
$(error Unsupported operating system: $(UNAME_S))
endif

.PHONY: build test install clean
all: lint build test install clean

lint:
cargo clippy

build:
cargo build --release

test: build
php -d extension=./target/release/libaerospike$(EXTENSION) test.php

install: build
sudo cp -f target/release/libaerospike$(EXTENSION) $(EXT_DIR_PATH)
echo "extension=libaerospike$(EXTENSION)" | sudo tee -a $(PHP_INI_PATH)
$(RESTART_COMMAND)

clean:
cargo clean
61 changes: 60 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,60 @@
Aerospike's new PHP library implementation. Still cooking...
## This project is pre-alpha, and should not be used in production. If you're an enterprise customer feel free to reach out to our support with feedback and feature requests. We appreciate feedback from the Aerospike community on issues related to the new PHP client.

# Aerospike [email protected] Client

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

## Requirements

* PHP 8.1
* Composer
* cargo
* Aerospike server v5.7+

## Setup

How to setup:
* Follow [this guide](https://davidcole1340.github.io/ext-php-rs/getting-started/installation.html) and install PHP 8.1 *from source*.
* Build and run the code via: `cargo build && php -d extension=./target/debug/libaerospike.so test.php` for linux or `cargo build && php -d extension=./target/debug/libaerospike.dylib test.php` for darwin
* Use Aerospike Server v5.7 for testing; The Rust client does not support the newer servers entirely.

## Documentation
* Php stubs and documentation can be found [here](https://github.com/aerospike/php-client/blob/php-rs/php_code_stubs/php_stubs.php)
* GeoFilter examples can be found [here](https://github.com/aerospike/php-client/php-rs/blob/examples/geoQueryFilter.php)

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

```php

<?
$cp = new ClientPolicy();
$client = Aerospike($cp, "127.0.0.1:3000");
$key = new Key("test", "test", 1);

$wp = new WritePolicy();
$bin1 = new Bin("bin1", 111);
$client->put($wp, $key, [$bin1]);

$client->prepend($wp, $key, [new Bin("bin2", "prefix_")]);

$client->append($wp, $key, [new Bin("bin2", "_suffix")]);

$rp = new ReadPolicy();
$record = $client->get($rp, $key);
var_dump($record->bins);

$deleted = $client->delete($wp, $key);
var_dump($deleted);

$exists = $client->exists($wp, $key);
var_dump($exists);

$client->close();

```





23 changes: 23 additions & 0 deletions build/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Check PHP Version
required_php_version="8.1"

installed_php_version=$(php -r "echo PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION;")
if [ "$installed_php_version" != "$required_php_version" ]; then
echo "Error: PHP version $required_php_version is required, but you have PHP $installed_php_version installed."
exit 1
fi

# Download PHP Client Code
github_repo="https://github.com/aerospike/php-client"
branch="main"

git clone -b $branch $github_repo
cd php-client

# Run Make File
make

# Clean up: Optionally remove the cloned repository after building
rm -rf ../php-client # Uncomment this line if you want to remove the cloned repository
1 change: 1 addition & 0 deletions build/php-client
Submodule php-client added at 4f6644
24 changes: 24 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "aerospike/aerospike-php",
"type": "library",
"version": "v0.1.0-alpha1",
"description": "Aerospike PHP Extension Pre-Alpha",
"keywords": ["php", "extension"],
"license": "Apache-2.0",
"authors": [
{
"name": "Sachin Venkatesha Murthy",
"email": "[email protected]"
},
{
"name": "Khosrow Afroozeh",
"email": "[email protected]"
}
],
"require": {
"php": ">=8.1"
},
"scripts": {
"post-install-cmd": ["cd build && sh build.sh"]
}
}
20 changes: 20 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
log_level: info
log_file_path: myapp.log
63 changes: 63 additions & 0 deletions examples/geoQueryFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

function createClient() {
$cp = new ClientPolicy();
$client = Aerospike($cp, "127.0.0.1:3000");
return $client;
}

////////////////////////////////////////////////////////////////////////////////
//
// Filter -> Geo2DSphere
//
////////////////////////////////////////////////////////////////////////////////


function insertData($client) {
echo "Inserting test data ... \n";
$circleFormat = '{"type":"AeroCircle","coordinates":[[%f,%f], %f]}';
$target_string = sprintf($circleFormat, -80.590000, 28.60000, 1000);
$geoLoc = new Bin("bottom_targets", Value::geoJson($target_string));
$key = new Key("test", "testGeo", "geoKey");
$wp = new WritePolicy();
$client->put($wp, $key, [$geoLoc]);

}


function getBins($client) {
echo "Getting Test data ... \n";
$key = new Key("test", "testGeo", "geoKey");
$rp = new ReadPolicy();
$record = $client->get($rp, $key);
var_dump($record);
}

function geoFilter($client) {
echo "Query point data ... \n";
$lng = -80.590003;
$lat = 28.60009;

$point_string = '{"type":"Point","coordinates":[-80.590003, 28.60009]}';
$statement = new Statement("test", "deliverySet");
$statement->filters = [Filter::regionsContainingPoint("area", $point_string)];
$qp = new QueryPolicy();
$recordset = $client->query($qp, $statement);

if ($recordset === false) {
echo "Error querying the database: " . $client->error() . "\n";
exit(1);
}

echo "Record set... \n";
while ($rec = $recordset->next()) {
var_dump($rec->bins);
}
}

$client = createClient();
// insertData($client);
// getBins($client);
// geoFilter($client);

$client->close();
Loading

0 comments on commit a7a99dd

Please sign in to comment.