Thursday, June 30, 2011

PHP5-Memcached 釘文

Q1 31 Jun
PHP Warning: Unknown: Failed to write session data (memcached). Please verify that the current setting of session.save_path is correct (tcp://127.0.0.1:11211) in Unknown on line 0

成因:
$mcdhost = '127.0.0.1';
$mcdport = '11211';
ini_set('session.save_handler', 'memcached'); 有d
ini_set('session.save_path', $session_save_path);
其中$session_save_path = "$mcdhost:$mcdport";
不是$session_save_path = "tcp://$mcdhost:$mcdport";僅用於php5-memcache

Q2 31 Jun
PHP Warning: Unknown: Failed to write session data (memcached). Please verify that the current setting of session.save_path is correct (127.0.0.1:11211) in Unknown on line 0

成因:
故意停止Memcached 服務器後運行Memcached::addServer(),本打算用if/try{}catch 判斷若不能連接Memcached Server則用回files形式儲存,雖php手冊中指addServer()返回為TRUE或FALSE但判斷未成功,只出現上述警告
這方面用php5-memcache的Memcache::connect()較好, 因為若不成功連接會返回false。出現的錯誤用@抑止後不影响session header的輸出,退回用file儲存session方式

http://www.gocar.idv.tw/phpbb3/viewtopic.php?f=24&p=79
試例子只適用於php5-memcache
在php.ini 中預設session.save_handler = files 和 session.save_path = /path_to_file/

Q3 31 Jun
用Memcached server處理http session cookie,但有個問題是未能控制session cookie何時因閒置而過期問題。
是否與只在php程序中用ini_set()修改了session handler 而非在php.ini中修改,因此garbage collection 不會在預設1440秒後清除閒置的session?
1 July
在PHP5-MEMCACHE(NO d)的PHP script 中設了 int_set('session.gc_maxlifetime', 20); telnet查看該session 雖然不一定刪除該key,但Memcached server 還是會清去其內的value,但此轉到用PHP5-MEMCACHED(WITH D)中在Pphp.ini中設了session.save_handler = memcached及session.gc_maxlifetime = 30,當中的key-value即使逾時還是會保留,打開verbose -vv tail -f /var/log/memcached.log 觀察,有定期delete key 的紀錄(可能因client端的app定期更新行為)

2008年一篇對memcached garbage collector 的討論電郵
http://lists.danga.com/pipermail/memcached/2008-May/006849.html
Memcache(d) to store PHP sessions 比較php-memcache和php-memcached
http://beeznest.wordpress.com/2011/04/18/memcached-to-store-php-sessions/

php5-memcached 不會清除過期的session(的值, key會保留),試過改session.gc_maxlifetime session.gc_probability/session.gc_divisor =1/1 但仍然無效,估計可能在寫入memcached時expire time為0(即不過期)有關,未找到如何修改,或者需要重新override session_save_handler()。用PHP5-Memcach則會自動清理,改用這。

13 comments:

Anonymous said...

cialis online cialis price thailand - super cialis cheap

Anonymous said...

buy tramadol online order tramadol online with mastercard - tramadol dosage for opiate withdrawal

Anonymous said...

buy tramadol online purchase tramadol cod shipping - tramadol 50 mg medicine

Anonymous said...

buy tramadol tramadol many get high - tramadol 100mg online overnight

Anonymous said...

buy tramadol tramadol 50 mg price street - tramadol dose to get high

Anonymous said...

tramadol 100 cheap tramadol eu - online us pharmacy no prescription tramadol

Anonymous said...

http://buytramadolonlinecool.com/#30694 buy tramadol online in florida - tramadol withdrawal 3 days

Anonymous said...

http://landvoicelearning.com/#63987 tramadol nsaid - tramadol withdrawal tips

Anonymous said...

buy tramadol tramadol 50mg 319 - buy tramadol online with credit card

Anonymous said...

purchase ativan ativan dosage instructions - ativan uses for

Anonymous said...

http://staam.org/#21236 tramadol kick in time - buy tramadol cod overnight

Anonymous said...

cheap alprazolam effects mixing xanax klonopin - what does 1mg generic xanax look like

Anonymous said...

http://bayshorechryslerjeep.com/#2mg drug interactions xanax tylenol - price of 2mg xanax