Home | Mirror | Search

2. PHP Memcache

參考PHP安裝

2.1. pecl

進入PHP工作目錄

cd /usr/local/php/
			

安裝 memcache

pecl install

bin/pecl install memcache
			

php.ini

			
vi etc/php.ini

extension_dir = "/usr/local/php-5.3.3/lib/php/extensions/"
extension = memcache.so
			
			

php.ini memcache 參數

			
cat >> /usr/local/php/etc/php.ini <<EOF
[memcache]
memcache.allow_failover = 1
memcache.max_failover_attempts=20
memcache.chunk_size =8192
memcache.default_port = 11211
memcache.default_timeout_ms=30
EOF
			
			

2.2. apt-get

$ sudo apt-get install php5-memcache
			

memcache.ini 檔案

$ cat /etc/php5/conf.d/memcache.ini
; uncomment the next line to enable the module
extension=memcache.so

[memcache]
memcache.dbpath="/var/lib/memcache"
memcache.maxreclevel=0
memcache.maxfiles=0
memcache.archivememlim=0
memcache.maxfilesize=0
memcache.maxratio=0
			

2.3. example

例 19.2. memcache.php

				
<?php
	$memcache = new Memcache;
	$memcache->connect('localhost', 11211) or die ("Could not connect");

	$memcache->set('var_key', 'some really big variable', MEMCACHE_COMPRESSED, 50);
	echo $memcache->get('var_key');
?>
				
				

運行測試腳本

php -q memcache.php
				

comments powered by Disqus