Memcached 已经正确安装配置, 并且防火墙也已经打开了本机对自己所有端口的访问, telnet localhost 11211也正常, 但是通过PHP访问出现

[Sat May 17 22:02:42 2014] [error] [client 59.109.104.166] PHP Warning: Memcache::connect(): Can't connect to 127.0.0.1:11211, Permission denied (13) in /var/www/html/test.php on line 8

这是由于SELinux的配置引起的. 通过 sudo getenforce 可以看到 SELinux 处于打开状态, 这时候可以通过这个命令允许httpd对本机其他服务的访问:

sudo setsebool httpd_can_network_connect=1

用于测试memcached的PHP脚本:

connect($server);

    if ($isMemcacheAvailable) {
$aData = $memcache->get('data');
echo '
';
if ($aData) {
echo '

Data from Cache:

';
print_r($aData);
} else {
$aData = array(
'me' => 'you',
'us' => 'them',
);
echo '

Fresh Data:

';
print_r($aData);
$memcache->set('data', $aData, 0, 300);
}
$aData = $memcache->get('data');
if ($aData) {
echo '

Memcache seem to be working fine!

';
} else {
echo '

Memcache DOES NOT seem to be working!

';
}
echo '
'; } } if (!$isMemcacheAvailable) { echo 'Memcache not available'; } ?>

25 sudo getenforce

26 sudo ifconfig

27 sudo vi /etc/rc.d/init.d/memcached

28 sudo setsebool httpd_can_network_connect=1

04-15 21:10