美文网首页
2018-02-02

2018-02-02

作者: icepig | 来源:发表于2018-02-02 10:37 被阅读0次

    PHP7 Memcached CAS 变化

    服务器升级PHP7后发现一些Memcached的get和getMulti方法的Warning,查阅了一下官方文档,原来PHP7中Memcached扩展的CAS实现有所变化:

    As of some version of php7 (i was not able to determine which exactly).
    The $cas_token is no longer valid argument. It has been removed in favor of flags argument, as it appears to be causing issues when subclassing the Memcached class.
    
    See https://github.com/php-memcached-dev/php-memcached/pull/214 for more details.
    
    Basically you need to 
    <?php
    function memcacheGet($key, $cb = null, &$cas = null) {
      $m = memcacheGetObject();
      if(empty($m))
        return false;
      if(defined('Memcached::GET_EXTENDED')) {
        //Incompatible change in php7, took me 2 hours to figure this out, grrr
        $_o = $m->get($key, $cb, Memcached::GET_EXTENDED);
        $o = $_o['value'];
        $cas = $_o['cas'];
      } else {
        $o = $m->get($key, $cb, $cas);
      }
      return $o;
    }
    ?>
    

    PHP7中用Memcached::GET_EXTENDED参数表示获取cas,token不再以引用方式获取而是直接返回,getMulti也是一样。

    相关文章

      网友评论

          本文标题:2018-02-02

          本文链接:https://www.haomeiwen.com/subject/iouszxtx.html