答: 我不得不将 PREDIS_BASE_PATH 的路径更改为 predis/lib/。
我想在 PHP 文件中加载 predis,但我遇到了麻烦。我正在按照 predis github 网站 (https://github.com/nrk/predis) 上加载 predis 的指南进行操作。这是我用来加载 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,
));
这是我得到的错误:
Fatal error: Class 'Predis\Client' not found
编辑:应该导入predis目录中的什么文件?更改文件夹权限后,我可以回显 $file 所持有的变量:“文件变量是:predis/Predis/Client.php”
根据此处列出的目录https://github.com/nrk/predis,没有 client.php 文件。