xsmscb 发表于 2015-8-31 09:14:24

阿里云主机安装memcache扩展

   php扩展memcache的作用是为了支持memcached数据库缓存服务器,下面是安装方法。
1、下载并解压memcache文件



view plaincopy

[*]wget -c http://pecl.php.net/get/memcache-3.0.6.tgz
[*]tar xzvf memcache-3.0.6.tgz
[*]cd memcache-3.0.6
  2、执行phpize扩展安装程序,假设phpzie的路径为/usr/local/php/bin/phpize,具体的路径得根据自己的环境修改。



view plaincopy

[*]/alidata/server/php-5.2.17/bin/phpize
  3、开始安装扩展memcache



view plaincopy

[*] ./configure --enable-memcache --with-php-config=/alidata/server/php-5.2.17/bin/php-config --with-zlib-dir
[*]make && make install
  安装完成后,提示



view plaincopy

[*]Installing shared extensions:   /alidata/server/php/lib/php/extensions/no-debug-zts-20060613/
  4、最后修改php.ini文件,在zend之前(这个似乎是必须的,不能放到最后)加入如下代码。



view plaincopy

[*]
[*]extension_dir = "/alidata/server/php/lib/php/extensions/no-debug-zts-20060613/"
[*]extension=memcache.so
  到这里就安装结束了,重新加载php.ini配置后,打开phpinfo()看下是不是有memcache。
  附php的memcache测试代码:



view plaincopy

[*]<?php
[*]$memcache = new Memcache;
[*]$memcache->connect('127.0.0.1', 11211) or die ("Could not connect");
[*]$version = $memcache->getVersion();
[*]echo "Server's version: ".$version."\n";
[*]$tmp_object = new stdClass;
[*]$tmp_object->str_attr = 'test';
[*]$tmp_object->int_attr = 123;
[*]$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
[*]echo "Store data in the cache (data will expire in 10 seconds)\n";
[*]$get_result = $memcache->get('key');
[*]echo "Data from the cache:\n";
[*]var_dump($get_result);
[*]?>
页: [1]
查看完整版本: 阿里云主机安装memcache扩展