无法在 Judy 中插入任何值


Can't insert any values in Judy

我在使用Judy Array时遇到了奇怪的行为。文档只是说你可以像通常的PHP数组一样使用它。但无论我做什么,在我看来它都不会存储任何信息。

例如,如果我这样做:

$this->_history = new Judy(Judy::STRING_TO_MIXED);
$this->_history['test'] = 'testString';
echo $this->_history['test']; // output nothing; no warnings no text nothing
var_dump($this->_history); // class Judy#126 (0) { }
$this->_history->getType() // correctly (int) 5
$this->_history->getTypeFoo() // warning no method

我做错了什么吗?我忘记了什么吗?我测试了它,一个 Ubuntu 和 Debian 系统,两者都是一样的。

同样有趣的是,当我运行pecl包中提供的bench脚本并在/usr/share/php/doc/Judy/examples/judy-bench-string_to_int.php下提取时,Judy Array 工作正常。

这是我的安装方式:

sudo aptitude install libjudydebian1 libjudy-dev
sudo pecl install judy

它说安装成功,我extension=judy.so添加到php.ini
我应该怎么做才能让朱迪工作?

好吧,它现在可以工作了。但实际上我不知道为什么。我不应该在乎。我将bench-*.php文件中的工作代码从/docs复制到我自己的文件中,它起作用了。代码如下:

echo "'n-- Judy STRING_TO_INT 'n";
echo "Mem usage: ". memory_get_usage() . "'n";
echo "Mem real: ". memory_get_usage(true) . "'n";
$s=microtime(true);
$judy = new Judy(Judy::STRING_TO_MIXED);
for ($i=0; $i<500; $i++)
    $judy["$i"] = 'test';
var_dump($judy);
unset($judy["102"]);
echo $judy["192"];
var_dump($judy["102"]);
echo "Size: ".$judy->size()."'n";
$e=microtime(true);
echo "Elapsed time: ".($e - $s)." sec.'n";
echo "Mem usage: ". memory_get_usage() . "'n";
echo "Mem real: ". memory_get_usage(true) . "'n";
echo "'n";
unset($judy);