[root@localhost software]# tar zxvf libevent-1.4.11-stable.tar.gz [root@localhost libevent-1.4.11-stable]# ./configure –prefix=/usr [root@localhost libevent-1.4.11-stable]# make [root@localhost libevent-1.4.11-stable]# make install
[root@localhost libevent-1.4.11-stable]# ls -al /usr/lib | grep libevent lrwxrwxrwx 1 root root 22 07-10 13:10 libevent-1.1a.so.1 -> libevent-1.1a.so.1.0.2 -rwxr-xr-x 1 root root 31596 2007-01-07 libevent-1.1a.so.1.0.2 lrwxrwxrwx 1 root root 21 07-21 03:33 libevent-1.4.so.2 -> libevent-1.4.so.2.1.3 -rwxr-xr-x 1 root root 308088 07-21 03:33 libevent-1.4.so.2.1.3 -rw-r--r-- 1 root root 394474 07-21 03:33 libevent.a lrwxrwxrwx 1 root root 26 07-21 03:33 libevent_core-1.4.so.2 -> libevent_core-1.4.so.2.1.3 -rwxr-xr-x 1 root root 109490 07-21 03:33 libevent_core-1.4.so.2.1.3 -rw-r--r-- 1 root root 148742 07-21 03:33 libevent_core.a -rwxr-xr-x 1 root root 866 07-21 03:33 libevent_core.la lrwxrwxrwx 1 root root 26 07-21 03:33 libevent_core.so -> libevent_core-1.4.so.2.1.3 lrwxrwxrwx 1 root root 27 07-21 03:33 libevent_extra-1.4.so.2 -> libevent_extra-1.4.so.2.1.3 -rwxr-xr-x 1 root root 246870 07-21 03:33 libevent_extra-1.4.so.2.1.3 -rw-r--r-- 1 root root 307370 07-21 03:33 libevent_extra.a -rwxr-xr-x 1 root root 873 07-21 03:33 libevent_extra.la lrwxrwxrwx 1 root root 27 07-21 03:33 libevent_extra.so -> libevent_extra-1.4.so.2.1.3 -rwxr-xr-x 1 root root 831 07-21 03:33 libevent.la lrwxrwxrwx 1 root root 21 07-21 03:33 libevent.so -> libevent-1.4.so.2.1.3
[root@localhost software]# tar zxvf memcached-1.4.0.tar.gz [root@localhost memcached-1.4.0]# ./configure –with-libevent=/usr [root@localhost memcached-1.4.0]# make [root@localhost memcached-1.4.0]# make intall
[root@localhost memcached-1.4.0]# ls -al /usr/local/bin | grep memcached -rwxr-xr-x 1 root root 188225 07-21 03:35 memcached
[root@localhost software]# tar zxvf memcache-2.2.5.tgz [root@localhost software]# cd memcache-2.2.5 [root@localhost memcache-2.2.5]# /usr/bin/phpize [root@localhost memcache-2.2.5]# ./configure –enable-memcache –with-php-config=/usr/bin/php-config –with-zlib-dir [root@localhost memcache-2.2.5]# make [root@localhost memcache-2.2.5]# make install
extension_dir = "./"
extension_dir = "/usr/lib/php/modules"
[root@localhost src]# tar zxvf libmemcached-0.32.tar.gz [root@localhost src]# cd libmemcached-0.32 [root@localhost libmemcached-0.32]# ./configure --prefix=/usr [root@localhost libmemcached-0.32]# make && make install
[root@localhost src]# ls /usr/lib/libmemcache* //库文件 [root@localhost src]# ls /usr/include/libmemcached/* //头文件 [root@localhost src]# ls /usr/bin/mem* //命令行工具
[root@localhost bin]# service httpd restart
<?php
//连接
$mem = new Memcache;
$mem->connect("127.0.0.1", 11211);
echo 'Memcache Version is:'.$mem->getVersion().'<br/>';
//保存数据
$mem->set('key1', 'This is first memcache demo', 0, 60);
$val = $mem->get('key1');
echo "Get key1 value: ".$val."<br/>"
//关闭连接
$mem->close();
?>
<?php
$memcache = new memcache();
$memcache->addServer('127.0.0.1:1978');
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$time_start = microtime_float();
$data = 'abc123';
for($i = 0;$i <= 20000 ;$i++){
$key = (string) rand(1,100);
$memcache->set($key, $data);
}
for($i = 0;$i <= 20000 ;$i++){
$key = (string) rand(1,100);
echo $data = $memcache->get($key).'-'.$i.'<br/>';
}
$time_end = microtime_float();
$time = $time_end - $time_start;
echo $time;
$memcache->close();
?>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libmemcached/memcached.h>
int main(int argc, char *argv[])
{
memcached_st *memc;
memcached_return rc;
memcached_server_st *servers;
char value[8191];
//连接服务器
memc = memcached_create(NULL);
servers = memcached_server_list_append(NULL, "127.0.0.1",11211, &rc);
rc = memcached_server_push(memc, servers);
memcached_server_free(servers);
//存储数据
strcpy(value, "This is c first value");
rc = memcached_set(memc, "key1", 4, value, strlen(value),
(time_t)180, (uint32_t)0);
if (rc == MEMCACHED_SUCCESS) {
printf("Save key:key1 data:/"%s/" success./n", value);
}
//获取数据
char return_key[MEMCACHED_MAX_KEY];
size_t return_key_length;
char *return_value;
size_t return_value_length;
char *keys[]= {"key1"};
size_t key_length[]= {4};
uint32_t flags;
rc = memcached_mget(memc, keys, key_length, 1);
return_value = memcached_fetch(memc, return_key,
&return_key_length, &return_value_length, &flags, &rc);
if (rc == MEMCACHED_SUCCESS) {
printf("Fetch key:%s data:%s/n", return_key, return_value);
}
//删除数据
rc = memcached_delete(memc, "key1", 4, (time_t)0);
if (rc == MEMCACHED_SUCCESS) {
printf("Delete Key key1 success./n");
}
//释放内存
memcached_free(memc);
return 0;
}
[root@localhost html]# gcc -o cmem cmem.c -lmemcached [root@localhost html]# ./cmem //执行 Save key:key1 data:"This is c first value" success. Fetch key:key1 data:This is c first value Delete Key key1 success.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libmemcached/memcached.h>
int main(int argc, char *argv[])
{
memcached_st *memc;
memcached_return rc;
memcached_server_st *servers;
char value[8191];
//connect multi server
memc = memcached_create(NULL);
servers = memcached_server_list_append(NULL, "localhost", 11211, &rc);
servers = memcached_server_list_append(servers, "localhost", 11212, &rc);
rc = memcached_server_push(memc, servers);
memcached_server_free(servers);
//Save multi data
size_t i;
char *keys[]= {"key1", "key2", "key3"};
size_t key_length[]= {4, 4, 4};
char *values[] = {"This is c first value", "This is c second value", "This is c third value"};
size_t val_length[]= {21, 22, 21};
for (i=0; i <3; i++) {
rc = memcached_set(memc, keys[i], key_length[i], values[i], val_length[i], (time_t)180,(uint32_t)0);
if (rc == MEMCACHED_SUCCESS) {
printf("Save key:%s data:/"%s/" success./n", keys[i], values[i]);
}
}
//Fetch multi data
char return_key[MEMCACHED_MAX_KEY];
size_t return_key_length;
char *return_value;
size_t return_value_length;
uint32_t flags;
rc = memcached_mget(memc, keys, key_length, 3);
while ((return_value = memcached_fetch(memc, return_key, &return_key_length, &return_value_length, &flags, &rc))) {
if (rc == MEMCACHED_SUCCESS) {
printf("Fetch key:%s data:%s/n", return_key, return_value);
}
}
//Delete multi data
for (i=0; i <3; i++) {
rc = memcached_set(memc, keys[i], key_length[i], values[i], val_length[i], (time_t)180, (uint32_t)0);
rc = memcached_delete(memc, keys[i], key_length[i], (time_t)0);
if (rc == MEMCACHED_SUCCESS) {
printf("Delete %s success/n", keys[i], values[i]);
}
}
//free
memcached_free(memc);
return 0;
}
[root@localhost html]# gcc -o cmultmem cmultmem.c -lmemcached [root@localhost html]# ./cmultmem //执行 Save key:key1 data:"This is c first value" success. Save key:key2 data:"This is c second value" success. Save key:key3 data:"This is c third value" success. Fetch key:key2 data:This is c second value Fetch key:key3 data:This is c third value Fetch key:key1 data:This is c first value Delete key1 success Delete key2 success Delete key3 success
[root@localhost html]# ps aux | grep memcached root 11382 0.0 0.7 55124 1896 ? Ssl 13:06 0:00 memcached -d -m 100 -u root -l 127.0.0.1 -p 11211 -c 256 -P /tmp/memcached.pid root 11395 0.0 0.2 3912 664 pts/1 R+ 13:08 0:00 grep memcached
[root@localhost html]# kill `cat /tmp/memcached.pid`
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有