网络浪子 发表于 2018-12-20 11:18:40

php操作memcache的使用测试总结

转自新浪博客, 纯做收藏学习之用。 浏览用户请访问原地址:http://blog.sina.com.cn/s/blog_4dbe98f10100bqkr.html      1.简介
  memcache模块是一个高效的守护进程,提供用于内存缓存的过程式程序和面向对象的方便的接口,特别是对于设计动态web程序时减少对数据库的访问。
  memcache也提供用于通信对话(session_handler)的处理。
  更多Memcache 模块相关信息可以到 http://www.danga.com/memcached/ 查阅。
1.1.memcache在php.ini中的配置项列表 memcache在php.ini中的配置项列表  名称
  默认值
  是否可变
  改变日志
  memcache.allow_failover
  “1”
  PHP_INI_ALL
  Available since memcache 2.0.2.
  memcache.max_failover_attempts
  "20"
  PHP_INI_ALL
  Available since memcache 2.1.0.
  memcache.chunk_size
  "8192"
  PHP_INI_ALL
  Available since memcache 2.0.2.
  memcache.default_port
  "11211"
  PHP_INI_ALL
  Available since memcache 2.0.2.
  memcache.hash_strategy
  "standard"
  PHP_INI_ALL
  Available since memcache 2.2.0.
  memcache.hash_function
  "crc32"
  PHP_INI_ALL
  Available since memcache 2.2.0.
  session.save_handler
  "files"
  PHP_INI_ALL
  Supported since memcache 2.1.2
  session.save_path
  ""
  PHP_INI_ALL
  Supported since memcache 2.1.2
  有关 PHP_INI_* 常量进一步的细节与定义参见PHP手册php.ini 配置选项。
1.2.以下是配置项的简要解释  memcache.allow_failover Boolean
  在错误时是否透明的故障转移到其他服务器上处理(注:故障转移是动词)。
  memcache.max_failover_attempts integer
  定义服务器的数量类设置和获取数据,只联合 memcache.allow_failover 一同使用。
  memcache.chunk_size integer
  数据将会被分成指定大小(chunk_size)的块来传输,这个值(chunk_size)越小,写操作的请求就越多,如果发现其他的无法解释的减速,请试着将这个值增大到32768.
  memcache.default_port string
  当连接memcache服务器的时候,如果没有指定端口这个默认的tcp端口将被用。
  memcache.hash_strategy string
  控制在映射 key 到服务器时使用哪种策略。设置这个值一致能使hash 算法始终如一的使用于服务器接受添加或者删除池中变量时将不会被重新映射。设置这个值以标准的结果在旧的策略被使用时。
  memcache.hash_function string
  控制哪种 hsah 函数被应用于 key映射 到服务器过程中,默认值“crc32”使用 CRC32 算法,而“fnv”则表示使用 FNV-1a 算法。
  session.save_handler string
  通过设置这个值为memcache来确定使用 memcache 用于通信对话的处理(session handler)。
  session.save_path string
  定义用于通话存储的各服务器链接的分隔符号,例如:“tcp://host1:11211, tcp://host2:11211”。
  每服务器个链接可以包含被接受于该服务器的参数,比较类似使用 Memcache::addServer() 来添加的服务器,例如:“tcp://host1:11211?persistent=1&weight=1&timeout=1& amp;retry_interval=15”。
1.3.memcache常量列表 memcache常量列表  名称
  类型
  描述
  MEMCACHE_COMPRESSED
  integer
  用于调整在使用 Memcache::set(), Memcache::add() 和 Memcache::replace() 几个函数时的压缩比率。
  MEMCACHE_HAVE_SESSION
  integer
  如果通信对话的处理(session handler)被允许使用其值为 1,其他情况值为 0。
2Memcache Functions 函数列表2.1.Memcache::connect2.1.1.说明  bool Memcache::connect ( string $host [, int $port [, int $timeout ]] )
  连接memcache服务器
2.1.2.参数  $host(string)服务器域名或ip
  $port(int)服务器tcp端口号,默认值是11211
  $timeout连接memcache进程的失效时间,在修改它的默认值1的时候要三思,以免失去所有memcache缓存的优势导致连接变得很慢。
2.1.3.返回值  如果成功则返回true,失败则返回false
2.1.4.范例
页: [1]
查看完整版本: php操作memcache的使用测试总结