memcache(d)在ubuntu 13.10上不起作用


memcache(d) does not work on ubuntu 13.10

我正在尝试在我的apache上使用memcache。(徐本图13.10)我在这里安装了Apache2.4、Php5、Mysql5、php-pear等:https://www.digitalocean.com/community/articles/how-to-install-and-use-memcache-on-ubuntu-12-04

php-m

root@benjamin:~# php -m
[PHP Modules]
bcmath
bz2
calendar
Core
ctype
curl
date
dba
dom
ereg
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
json
libxml
mbstring
memcache
mhash
mysql
mysqli
openssl
pcntl
pcre
PDO
pdo_mysql
Phar
posix
readline
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
standard
sysvmsg
sysvsem
sysvshm
tokenizer
wddx
xml
xmlreader
xmlwriter
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcache

ps aux

root@benjamin:~# ps aux | grep memcached
www-data 16113  0.0  0.0 325400   916 ?        Ssl  12:10   0:00 memcached -d -m 128 -l 127.0.0.1 -p 11211 -vv -u www-data
root     16178  0.0  0.0  18008   956 pts/1    S+   12:16   0:00 grep --color=auto memcached

以及我使用的示例php代码

<?php 
  $memcache = new Memcache;
  $memcache->connect("localhost",11211); # You might need to set "localhost" to "127.0.0.1"
  echo "Server's version: " . $memcache->getVersion() . "<br />'n";
  $tmp_object = new stdClass;
  /*
  $tmp_object->str_attr = "test";
  $tmp_object->int_attr = 123;
  $memcache->set("key",$tmp_object,false,50);
  */
  $stat = $memcache->getExtendedStats();
  echo "Store data in the cache (data will expire in 10 seconds)<br />'n";
  echo "<pre>";
  print_r($stat);
   echo "Data from the cache:<br />'n";
  print_r($memcache->get("key"));
?>

问题是,什么都没发生。全白色页面。我怎样才能做到这一点?P.S:我还尝试连接127.0.0.1而不是localhost。

更新,我配置了php.ini,现在我可以得到错误了。

Warning: Unknown: failed to open stream: Permission denied in Unknown on line 0
Fatal error: Unknown: Failed opening required '/var/www/memcache.php' (include_path='.:/usr/share/php') in Unknown on line 0

Hej bencagri,

确保您已经安装了php5-memcached(如果您是debian,则为php5-memcache)。

创建一个phpinfo.php文件并编写

<?php
 echo phpinfo();
?>

并且有memcache,如果你找不到任何东西,你就必须使用

sudo a2enmod mem_cache

模块2。

重新启动您的apache,然后重试。

Patrick