阿里雲主機安裝memcache擴展


 php擴展memcache的作用是為了支持memcached數據庫緩存服務器,下面是安裝方法。
1、下載並解壓memcache文件

[plain]  view plain copy
 
  1. wget -c http://pecl.php.net/get/memcache-3.0.6.tgz  
  2. tar xzvf memcache-3.0.6.tgz  
  3. cd memcache-3.0.6  

2、執行phpize擴展安裝程序,假設phpzie的路徑為/usr/local/php/bin/phpize,具體的路徑得根據自己的環境修改。

[plain]  view plain copy
 
  1. /alidata/server/php-5.2.17/bin/phpize

3、開始安裝擴展memcache

[plain]  view plain copy
 
  1.  ./configure --enable-memcache --with-php-config=/alidata/server/php-5.2.17/bin/php-config --with-zlib-dir  
  2. make && make install  

安裝完成后,提示

[plain]  view plain copy
 
  1. Installing shared extensions:     /alidata/server/php/lib/php/extensions/no-debug-zts-20060613/ 

4、最后修改php.ini文件,在zend之前(這個似乎是必須的,不能放到最后)加入如下代碼。

[plain]  view plain copy
 
  1. [memcache]  
  2. extension_dir = "/alidata/server/php/lib/php/extensions/no-debug-zts-20060613/"  
  3. extension=memcache.so  

到這里就安裝結束了,重新加載php.ini配置后,打開phpinfo()看下是不是有memcache。

附php的memcache測試代碼:

[php]  view plain copy
 
  1. <?php  
  2. $memcache = new Memcache;  
  3. $memcache->connect('127.0.0.1', 11211) or die ("Could not connect");  
  4. $version = $memcache->getVersion();  
  5. echo "Server's version: ".$version."\n";  
  6. $tmp_object = new stdClass;  
  7. $tmp_object->str_attr = 'test';  
  8. $tmp_object->int_attr = 123;  
  9. $memcache->set('key'$tmp_object, false, 10) or die ("Failed to save data at the server");  
  10. echo "Store data in the cache (data will expire in 10 seconds)\n";  
  11. $get_result = $memcache->get('key');  
  12. echo "Data from the cache:\n";  
  13. var_dump($get_result);  
  14. ?>  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM