我终于在家用电脑上运行了memcache,所以我终于可以开始使用它了!
虽然我正在尝试使用代码,但我没有一个好的开始
php.net @memcache-set 我无法获得他们发布的示例代码
我试过这个:
然后
connect('memcache_host', 11211); $memcache_obj->set('var_key', 'some really big variable', MEMCACHE_COMPRESSED, 50); echo $memcache_obj->get('var_key'); ?>
并从上面的代码中得到了这些错误;
Warning: Memcache::connect() [memcache.connect]: Can't connect to memcache_host:11211, A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (10060) in C:\webserver\htdocs\test\memcache\index.php on line 36 Warning: Memcache::set() [memcache.set]: Failed to extract 'connection' variable from object in C:\webserver\htdocs\test\memcache\index.php on line 42 Warning: Memcache::get() [memcache.get]: Failed to extract 'connection' variable from object in C:\webserver\htdocs\test\memcache\index.php on line 44
然后我在网上找到了这个代码,它确实有效
connect('localhost', 11211) or die ("Could not connect"); $tmp_object = new stdClass; $tmp_object->str_attr = 'test'; $tmp_object->int_attr = 123; // add cache $memcache->set('key', $tmp_object, false, 30) or die ("Failed to save data at the server"); echo "Store data in the cache (data will expire in 30 seconds)
\n"; // get cache $get_result = $memcache->get('key'); echo "Data from the cache:
\n"; var_dump($get_result); ?>
我怎样才能从PHP.net中获取示例?
此外,我很想看到任何涉及memcache的emample代码,你可能想要分享我真的很感激看到一些有用的例子
您是否意识到需要将"memcache_host"替换为您的主机名和/或localhost?还是我完全忽略了这一点?此外,尝试telnet localhost 11211
然后telnet your-memcache-host-name 11211
看看你是否得到相同的结果(你应该).