[英]Problems using Codeigniter with Memcached
我在我管理的应用程序中将Codeigniter 2.1.4与PHP 5.5一起使用。 我一直在测试Memcached以提高应用程序的性能,并且昨天运行良好。
今天,我打算现场部署它,但是经过一些改进,我注意到它不再起作用了。 在生产环境中,我将使用AWS Elasticache(它也不适用于我的暂存环境-但此问题的目的是让它在我的本地主机上重新运行,此后我将担心Elasticache)。
在一切之前,在MAMP的php信息中,我看到:
memcached support enabled
Version 2.2.0
libmemcached version 1.0.18
SASL support yes
Session support yes
igbinary support no
json support no
msgpack support no
在codeigniter application / config / development /上,我有一个名为memcached.php的文件,其内容如下:
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
$config = array(
'default' => array(
'host' => 'localhost',
'port' => 11211,
'weight' => 1
)
);
我的测试很简单。 我有一个具有此功能的控制器:
public function memcached(){
$this->load->driver('cache');
if($this->cache->memcached->is_supported()){
$data = $this->cache->memcached->get('foo');
if (!$data){
echo 'cache miss!<br />';
$data = 'bar';
$this->cache->memcached->save('foo',$data, 60);
}
echo $data;
echo '<pre>';
var_dump($this->cache->memcached->cache_info());
echo '</pre>';
}
}
输出(总是)是这样的:
cache miss!
bar
array(1) {
["localhost:11211"]=>
array(24) {
["pid"]=>
int(-1)
["uptime"]=>
int(0)
["threads"]=>
int(0)
["time"]=>
int(0)
["pointer_size"]=>
int(0)
["rusage_user_seconds"]=>
int(0)
["rusage_user_microseconds"]=>
int(0)
["rusage_system_seconds"]=>
int(0)
["rusage_system_microseconds"]=>
int(0)
["curr_items"]=>
int(0)
["total_items"]=>
int(0)
["limit_maxbytes"]=>
int(0)
["curr_connections"]=>
int(0)
["total_connections"]=>
int(0)
["connection_structures"]=>
int(0)
["bytes"]=>
int(0)
["cmd_get"]=>
int(0)
["cmd_set"]=>
int(0)
["get_hits"]=>
int(0)
["get_misses"]=>
int(0)
["evictions"]=>
int(0)
["bytes_read"]=>
int(0)
["bytes_written"]=>
int(0)
["version"]=>
string(0) ""
}
}
有趣的是,如果我在该memcached.php配置文件中编辑memcached的主机地址,它仍然会输出[“ localhost:11211”] 。
更新:
我刚刚使用新鲜下载的Codeigniter 2.1.4文件创建了一个干净的应用程序,并且都一样。
干杯!
您应该检查memcached服务是否正在运行。 您的结果显示pid(进程ID)为-1,正常运行时间为0秒。
服务器上需要运行实际的memcached服务,您可以通过尝试telnet到localhost上的端口11211来检查其是否在正确侦听。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.