• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

PHP缓存应用:PHP MEMCACHE 详解_PHP

php 搞代码 3年前 (2022-01-25) 9次浏览 已收录 0个评论

memcacheEMC

Memcache函数库是在PECL(PHP Extension Community Library)中,主要作用是搭建大容量的内存数据的临时存放区域,在分布式的时候作用体现的非常明显,否则不建议使用。在ubuntu上安装完运行的时候报错:

/usr/local/memcached/bin/memcached: error while loading shared libraries: libevent-1.4.so.2:

cannot open shared object file: No such file or directory

按照:《libeven、memcached、libmemcache安装》中的方法,使用:

sudo ln -s /usr/local/lib/libevent-1.4.so.2 /usr/lib/libevent-1.4.so.2

可以修正这个BUG

通过新得立安装php的memcached模块,注销/etc/php5/conf.d/memcached.ini里面的“;”,重启apache,调用phpinfo()出现memcached的信息。

<?php
$memcache = new Memcache;
$memcache->connect(‘localhost’, 11211) or die (“Could not connect”);
$version = $memcache->getVersion();
echo “Server’s version: “.$version.”\n”;
?>
  1. <?php
  2. $memcache = new Memcache;
  3. $memcache->connect(‘localhost’, 11211) or die (“Could not connect”);
  4. print_r($memcache->getStats());
  5. /**
  6. * Array
  7. * (
  8. * [pid] => 8052
  9. * [uptime] => 9205
  10. * [time] => 1205898428
  11. * [version] => 1.2.5
  12. * [pointer_size] => 32
  13. * [rusage_user] => 0.008000
  14. * [rusage_system] => 0.000000
  15. * [curr_items] => 1
  16. * [total_items] => 17
  17. * [bytes] => 57
  18. * [curr_connections] => 2
  19. * [total_connections] => 15
  20. * [connection_structures] => 3
  21. * [cmd_get] => 9
  22. * [cmd_set] => 23
  23. * [get_hits] => 5
  24. * [get_misses] => 4
  25. * [evictions] => 0
  26. * [bytes_read] => 671
  27. * [bytes_written] => 850
  28. * [limit_maxbytes] => 10485760
  29. * [threads] => 1
  30. * )
  31. */
  32. ?>
01.<?php
02.$memcache = new Memcache;
03.$memcache->connect(‘localhost’, 11211) or die (“Could not connect”);
04.$memcache->set( ‘name’, ‘leo’, 0, 30);
05.if(!$memcache->add( ‘name’, ‘susan’, 0, 30))
06.{
07. echo ‘susan is exist’;
08.};
09.$memcache->replace( ‘name’, ‘l6本文来源gao@dai!ma.com搞$代^码!网7

搞gaodaima代码

ion’, 0, 300);
10.echo $memcache->get( ‘name’);
11.$memcache->delete( ‘name’, 5);
12.?>

01.<?php
02.function _callback_memcache_failure($host, $port) {
03. print “memcache ‘$host:$port’ failed”;
04.}
05.$memcache = new Memcache;
06.$memcache->addServer(‘192.168.1.116’, 11211);
07.$memcache->setServerParams(‘192.168.1.116’, 11211, 1, 15, true,
08.
09.’_callback_memcache_failure’);
10.echo $memcache->getServerStatus(‘192.168.1.116’, 11211);
11.?>
01.<?php
02.$memcache = new Memcache;
03.$memcache->connect(‘localhost’, 11211);
04.$memcache->set(‘test_item’, 8);
05.$memcache->increment(‘test_item’, 4);
06.echo $memcache->decrement(‘test_item’, 7);
07.// 显示 5
08.?>
/usr/local/bin/memcached -d -m 10 -u root -l 127.0.0.1 -p 11211 -c 256 -P

/tmp/memcached.pid


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP缓存应用:PHP MEMCACHE 详解_PHP
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址