dongsu3138 2012-07-27 22:37
浏览 17
已采纳

PHP memcache连接

I have a page where few thousands of users can hit a method at the same time . I do have following code where I connect every time . Since this will go to a seperate memcache server will this cause slowdowns is there a way to connect just once and reuse that connection ? Do I have to close connection after every request ?

$primary_connected = $memcache_primary->connect($primary_memcache_server, 11211);
if($primary_connected){
        $data = $memcache_primary->get($key);
        if ($data != NULL) {
            return data;
        }
 }
else{
/////Get data from database 
}
  • 写回答

1条回答 默认 最新

  • dongmi6102 2012-07-27 22:43
    关注

    If you are using the PHP memcached class (the one with the d on the end, not memcache) then yes, you can open a persistent connection.

    You can pass a persistent ID to the constructor which will open a persistent connection and subsequent instances that use the same persistent ID will use that connection.

    $memcached = new Memcached('method_name_or_persistent_identifier');
    $memcached->addServer(...);
    // use it
    

    Hope that helps.

    See Memcached::__construct() for more details.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改