【发布时间】:2011-10-25 17:27:19
【问题描述】:
我的问题是我的 cakePHP 应用程序中的 memcache 逻辑无法在我的本地系统上运行,自从我在这里设置它以来,通过从队友的现有设置中获取代码。我检查了 Memcached 服务是否在我的系统上运行,并且 phpinfo() 显示 memcache 部分已启用。
但是,这样的事情是行不通的 -
$this->Memcache->set($key,$value);
CakePHP 使用它的 Memcache 包装器,v. 0.3。
如果我这样调试 -
echo "<pre>";
echo "checking";
error_reporting(-1);
$this->Memcache->set($key,$countryNetworkWiseReportData,3600);
echo "finished";
exit;
我明白了-
检查完毕
严格标准:不应静态调用非静态方法 Cache::write(),假设 $this 来自第 690 行 D:\cake1.2\cake\libs\configure.php 中的不兼容上下文... 以及 Cache::getInstance() 等类似的严格标准通知。
但请注意,通知出现在“checkingfinished”之后,所以我很困惑这是否真的相关。
我试过命令-
telnet 127.0.0.1:11211
这给了-
Connecting To 127.0.0.1:11211...Could not open connection to the host, on port 23: Connect failed
也试过了-
telnet localhost:11211 (in case firewall issues prevent connection to 127.0.0.1)
但是遇到了同样的错误。
我还尝试了这个名为 memcache.php 的脚本。我在代码中输入了$arr= "127.0.0.1:11211";,然后在我的系统上得到了这个结果-
我从这些数据中解释了什么?我在开始时间部分收到警告 - Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the ...。
到目前为止,在我看来,连接到默认端口 11211 是由于我的 cakePHP 项目代码中不允许的某种原因。但同样,memcache.php 是如何连接到 memcache 服务器并能够显示这些数据的。
更多详情
感谢 Tudor Constantin,telnet 127.0.0.1 11211 不再抛出任何错误,显示一个空白屏幕......我想这很好。
我进一步检查了代码,我们有具有这样逻辑的模型函数 -
if(!$this->memcacheCommon())
{
$this->log('Error in memcache', LOG_DEBUG);
die('Error in memcache');
}
//like in others system, in my system too, it passes above condition
$memcachedata = $this->Memcache->get($key);
//does not return data in my system, because $this->Memcache->set($key,$data); never sets the data correctly.
if(got data from memcache)
{
//Return that data
}
else
{
//Get data from database
$this->Memcache->set($key,$data); //does not the data in my setup - set() function returns false
}
所以,我进入了 CakeMemcache() 类的 set() 函数,最后有这一行
return @$this->_Memcache_cluster_new->set($key, $var, 0, time()+$expires);
这返回 false,我不知道从这里调试什么。
让我感到困惑的另一件事是 app_model.php 中的 memcacheCommon() 有这些行 –
$this->Memcache = new CakeMemcache();
$this->Memcache->_connect();
而在 CakeMemcache()->_connect() 里面,有这几行——
$this->_Memcache_standalone =& new Memcache();
$this->_Memcache_cluster_new =& new Memcache();
我不确定他们到底是做什么的。
将不胜感激任何指针...谢谢
更多详情
我不知何故丢失了早期的 memcache.php 文件,使用它我得到了上面的图形 memcache 使用显示(上面已经发布了我得到的输出图片)。后来我从http://pecl.php.net/package/memcache/3.0.6 下载了 memcache-3.0.6 并尝试运行存档中存在的 example.php 和 memcache.php 文件。
首先,运行 example.php 会出现以下错误 -
Notice: memcache_connect(): Server localhost (tcp 11211) failed with: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Warning: memcache_connect(): Can't connect to localhost:11211, A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Connection to memcached failed
我检查了 memcached 服务是否正在运行(在 Windows 服务列表中)。
telnet localhost 11211 也没有给出任何错误并显示一个空的命令窗口。
其次,运行 memcache.php 并输入凭据,在单击所有选项卡(刷新数据、查看主机统计信息、变量)时给我以下信息 -
Notice: Use of undefined constant values - assumed 'values' in path\to\file\memcache.php on line 57
Cant connect to:v:a
第 57 行是 -
function get_host_port_from_server($server){
$values = explode(':', $server);
if (($values[0] == 'unix') && (!is_numeric( $values[1]))) {
return array($server, 0);
}
else {
return values; //line 57
}
}
这是价值观,我从http://pecl.php.net/package/memcache/3.0.6下载的。在我将其更改为 return $values; 后,我得到了 ->
Cant connect to:mymemcache-server1:11211
。我不完全记得我是多早获得那个 memcache 服务器图(我发布了上面的图片)。
第三,在命令行上,通过telnet连接后,命令stats给出如下-
STAT pid 1584
STAT uptime 2856
STAT time 1315981346
STAT version 1.2.1
STAT pointer_size 32
STAT curr_items 0
STAT total_items 0
STAT bytes 0
STAT curr_connections 1
STAT total_connections 3
STAT connection_structures 2
STAT cmd_get 0
STAT cmd_set 0
STAT get_hits 0
STAT get_misses 0
STAT bytes_read 7
STAT bytes_written 0
STAT limit_maxbytes 67108864
END
【问题讨论】:
-
我在哪里可以得到你正在显示的 memcache.php 脚本?
-
@Neo,你可以从pecl.php.net/package/memcache/3.0.6获得它 -> 下载最新链接。解压存档,将其中的
memcache.php文件放入您的Web 目录并浏览memcache.php。 PECL 应该已经安装好了。 -
在蛋糕配置中,memcache 服务器的设置在哪里? Memcache 可以有一个服务器集群,通常一个类包装器会遍历 memcache 服务器列表并尝试连接它们。
-
@gview - 发布了一些更多细节。
-
@Neo - 发布了更多详细信息。
标签: php cakephp windows-7 memcached telnet