[英]Problems using Codeigniter with Memcached
I'm using Codeigniter 2.1.4 with PHP 5.5 in an application I manage. 我在我管理的应用程序中将Codeigniter 2.1.4与PHP 5.5一起使用。 I've been testing Memcached to improve app's performance and it was working fine yesterday. 我一直在测试Memcached以提高应用程序的性能,并且昨天运行良好。
Today I was planning to deploy it live but after some improvements I noticed that it wasn't working anymore. 今天,我打算现场部署它,但是经过一些改进,我注意到它不再起作用了。 On production I'll use AWS Elasticache (which is also not working on my staging environment - but the purpose of this question is to get it back running on my localhost, after that I'll worry about Elasticache). 在生产环境中,我将使用AWS Elasticache(它也不适用于我的暂存环境-但此问题的目的是让它在我的本地主机上重新运行,此后我将担心Elasticache)。
Before everything, on MAMP's php info I see: 在一切之前,在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
On codeigniter application/config/development/ I have a file called memcached.php with this content: 在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
)
);
My test is simple. 我的测试很简单。 I have a controller with this function: 我有一个具有此功能的控制器:
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>';
}
}
And the output is (always) this: 输出(总是)是这样的:
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) ""
}
}
The funny thing is that if I edit memcached's host address in that memcached.php config file it still outputs ["localhost:11211"] . 有趣的是,如果我在该memcached.php配置文件中编辑memcached的主机地址,它仍然会输出[“ localhost:11211”] 。
UPDATE: 更新:
I've just created a clean application using fresh downloaded Codeigniter 2.1.4 files and it's all the same. 我刚刚使用新鲜下载的Codeigniter 2.1.4文件创建了一个干净的应用程序,并且都一样。
Cheers! 干杯!
You should check if the memcached service is running. 您应该检查memcached服务是否正在运行。 Your results show a pid (process id) of -1 and an uptime of 0 seconds. 您的结果显示pid(进程ID)为-1,正常运行时间为0秒。
There is an actual memcached service that needs to be running on the server, you can check if it's listening properly by trying telnet to port 11211 on localhost. 服务器上需要运行实际的memcached服务,您可以通过尝试telnet到localhost上的端口11211来检查其是否在正确侦听。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.