Fatal error: Class 'Aerospike' not found

1.2k Views Asked by At

I m try to load aerospike php api class but got error

Fatal error: Class 'Aerospike' not found

My code looks

<?php
require "vendor/autoload.php";

$config = [
    "hosts" => [
        [ "addr" => "127.0.0.1", "port" => 3000]
    ]
];


// The new client will connect and learn the cluster layout
$db = new Aerospike($config);

I m doing composer install and composer update what`s wrong ? If you need more files to show tell me.

2

There are 2 best solutions below

0
On

In order to use the Aerospike API client for PHP, you have to be able to compile C code and install the compiled extension on your server.

This requires an additional pack of installed packages than enable your machine to compile stuff, and it is way beyond the scope of Composer to provide any of these.

So this package looks innocent, but it is no genuine PHP Composer package. You cannot use it like any other package - all relevant classes like Aerospike are injected into PHP via the extension.

0
On

If you have install aerospike client you don't have to do require "vendor/autoload.php"; it works with extension.

First Install aerospike in any directory as documentation

git clone https://github.com/aerospike/aerospike-client-php.git
cd src/aerospike
./build.sh

To install the extension run inside src/aerospike:

make install

Create an aerospike.ini file at /etc/php/7.0/cli/conf.d with the directive:

extension=aerospike.so
aerospike.udf.lua_system_path=/usr/local/aerospike/lua
aerospike.udf.lua_user_path=/usr/local/aerospike/usr-lua

If you are using a web server such as Apache or Nginx you will need to copy aerospike.ini to the configuration include directory of the server, then issue a graceful restart.

⇒  ⇒  ⇒  Verify the Extension  ⇐  ⇐  ⇐
    php -m | grep aerospike