我已经采用了一些我之前使用过的memcache脚本没有问题,但在新页面上,我没有得到任何回复.
内存缓存位于另一个页面中的函数中.我所做的是将md5哈希值放入mysql查询并将其存储为memcached数据的密钥.如果密钥不在memcache中,那么我去创建数据,将其放入memcache并返回它.
我认为代码非常简单.这里有重要的部分(这是一个创建输出的大页面,所以你不需要所有这些,虽然我认为'返回'很重要,因为我担心这可能是我搞砸的地方.
我用这个函数调用
$outList.= outData($getList);
Run Code Online (Sandbox Code Playgroud)
其中$ getList是一个mysql查询
$ outList函数是
<?php
@$memcache = new Memcache;
@$memcache->connect("localhost",11211);
function outData($getList)
{
$memVal = @$memcache->get(MD5($getList));
if($memVal=='')
{
$results=mysql_query($getList)or die(mysql_error());
// then I do a bunch of stuff with the data
@$memcache->set(MD5($getList), $memVal, false, 60000);
}
return $memVal;
}
Run Code Online (Sandbox Code Playgroud)
我可以显示所有的东西来创建$ memVal,但我怀疑错误是在if行中,但是相同的代码在另一个页面上使用没有问题.
这有什么不妥吗?
所有那些@的压制错误,都无法知道失败的原因.
我跑了 - 没有@s的答案然后答案突然出现 - 在线:
$memVal = @$memcache->get(MD5($getList));
#Notice: Undefined variable: memcache in /home/topbit/736160.php on line 9
Run Code Online (Sandbox Code Playgroud)
它在哪里得到变量$ memcache?它没有传递给函数.