Rootop 服务器运维与web架构

memcached php测试页

| 暂无评论

<?php
$mem = new Memcache;
$mem->connect('192.168.1.11','11211');
$mem->set('key', 'This is a test!', 0, 60);
$val = $mem->get('key');
echo $val;
?>

注意ip地址,这里写在memcached启动时指定的监听地址。要不然会报错:

Notice: Memcache::connect(): Server 127.0.0.1 (tcp 11211) failed with: Connection refused (111) in /site/11/t.php on line 3 Warning: Memcache::connect(): Can’t connect to 127.0.0.1:11211, Connection refused (111) in /site/11/t.php on line 3 Warning: Memcache::set(): No servers added to memcache connection in /site/11/t.php on line 4 Warning: Memcache::get(): No servers added to memcache connection in /site/11/t.php on line 5

如果在启动memcached时,没有使用 -l  参数 指定监听ip地址的话,那么测试页中的ip地址可以为127.0.0.1、本机ip或者是localhost。

原创文章,转载请注明。本文链接地址: https://www.rootop.org/pages/1701.html

作者:Venus

服务器运维与性能优化

发表回复