CentOS 6 を実行しています。Apache を使用して php を処理し、nginx を使用してスクリプトの画像と css を処理します
memcached サーバーをインストールしました。
PORT="11211"
USER="memcached"
MAXCONN="4096"
CACHESIZE="512"
OPTIONS="-l 127.0.0.1"
PHP用のモジュールもインストールしました。
新しいphpファイルを作成しました
$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211) or die ("Could not connect");
memcached のステータスを確認したところ、実行中です。
いつも「接続できませんでした」と出ます。
値を「127.0.0.1」から「localhost」に変更しようとしましたが、まだ機能していません。
$memcache = new Memcache();
$memcache->addServer('127.0.0.1', 11211) or die ("Could not connect");
var_dump($memcache->getExtendedStats());
$memcache->set('key', 'hello world', false, 60);
echo $memcache->get('key');
//$memcache->connect('127.0.0.1', 11211) or die ("Could not connect");
出力
配列(1) { ["127.0.0.1:11211"]=> bool(false) }
connect と addServer の違いは何ですか? 最善の方法はどれですか?
しかし、私はHello Worldを取得していません
コードとこの問題に関するその他の更新..
phpinfoは memcached を示しています。
var_dump($memcache->get('key')); 与える
bool(偽)
connectの代わりにaddServerを使用する必要があるのはなぜですか?
コードのさらなる更新
$memcache = new Memcache;
$memcache->addServer('localhost', 11211);
echo $memcache->getServerStatus('localhost', 11211);
output : 1
//$memcache->set('key', 'hello world') or die("failed to store data");
output : failed to store data
もう少し詳細
getsebool httpd_can_network_memcache
それは戻ります
それは戻るべきですか?
Notice: Memcache::connect(): Server 127.0.0.1 (tcp 11211, udp 0) failed with: Permission denied (13)