Search code examples
phpaerospike

Class 'Aerospike' not found


Below is my code for aerospike connect.

<?php
$abhi ='test';
echo 'abhinav';
echo "\n";

connectAero('127.0.0.1');
function connectAero($hosts) {

        $config = array('hosts'=> $hosts);
        $db = new Aerospike(['hosts'=>[['addr'=>'127.0.0.1', 'port'=>3000]]]);
        if (!$db->isConnected()) {

                echo "<div class='alert alert-danger'> Aero Error ".$db->errorno(). ":". $db->error()."<div>";
                exit(1);

        }
        return $db;
}
?>

I am new to Aerospike and not much examples or documentation available, when above code is executed it throws an error as mentioned:

abhinav
PHP Fatal error:  Class 'Aerospike' not found in /home/ec2-user/aero.php on line 10
PHP Stack trace:
PHP   1. {main}() /home/ec2-user/aero.php:0
PHP   2. connectAero() /home/ec2-user/aero.php:6

What could be the thing which i am missing.


Solution

  • The mentioned was coming because Aerospike PHP client library/PHP extension was not installed. Download PHP extension files from below link:

    https://github.com/aerospike-community/aerospike-client-php5/releases/tag/3.4.15
    

    then run the build.sh script in the src/aerospike/ directory.

    cd src/aerospike
    ./build.sh
    
    Installing the PHP Extension-:
    make install
    php -i | grep ".ini 
    

    Now edit the php.ini file. If PHP is configured --with-config-file-scan-dir (usually set to /etc/php.d/) you can create an aerospike.ini file in the directory, otherwise edit php.ini directly. Add the following directive:

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

    Restart apache, this solution solved my problem.