Trouble loading predis on php website

egidra picture egidra · Jun 29, 2011 · Viewed 7.9k times · Source

Answer: I had to change the path of PREDIS_BASE_PATH to predis/lib/.

I want to load predis inside of a PHP file, but I am having trouble. I am following the guide to load predis on the predis github website (https://github.com/nrk/predis). Here is the code that I am using to load predis:

define("PREDIS_BASE_PATH", "predis/");
echo "The predis base path is: " . PREDIS_BASE_PATH . "\n";
spl_autoload_register(function($class) {
  $file = PREDIS_BASE_PATH . strtr($class, '\\', '/') . '.php';
  echo "The file variable is: " . $file . "\n";
  if (file_exists($file)) {
    require $file;
    return true;
  }
});

$redis = new Predis\Client(array(
  'host'  => 'localhost',
  'port'  => 6379,
));

Here is the error that I get:

Fatal error: Class 'Predis\Client' not found

Edit: What file in the predis directory should be imported? After changing the folder permissions, I am able to echo what the variable $file is holding: "The file variable is: predis/Predis/Client.php"

According to the directory listing here, https://github.com/nrk/predis, there is no client.php file.

Answer

Suhel Meman picture Suhel Meman · Jul 20, 2012

I use below code to connect predis on php page, and it worked fine.. below is code

<?php
        require "predis/autoloader.php";
        Predis\Autoloader::register();

        $redis = new Predis\Client(array(
         "scheme" => "tcp",
         "host" => "127.0.0.1",
         "port" => 6379));
?>