今天我離職了, 告別這大約兩年半的第一份工作。要來好好休息一陣子了。
不過我馬上就要趕回宜蘭, 明天是阿公做百日, 今天一定得趕回家的 Orz
RT @christiney35: 最近很多人介紹新朋友合作,真好。我也需要人家介紹 Python 工程師耶~快來吧,Python 工程師!! #fb
follow me on twitter這次我第一次開始用 memcached, 除了在 Google App Engine 上的 memcache 不算的話 XD
首先先裝 memcached, 我使用的是 gentoo linux
emerge memcached
接著裝上 pecl-memcache
emerge dev-php5/pecl-memcache
不過目前 amd64 平台的 pecl-memcache 套件還是 masked, 所以只好加上 ACCEPT_KEYWORDS 來安裝。
ACCEPT_KEYWORDS='~amd64' emerge dev-php5/pecl-memcache
然後把 www server 重開就可以開始用 memcache 了 :D 當然 memcached 也要記得開起來阿 XD
來個簡單的 php 範例:
$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211);
$memcache->set('key', 'value', false, 3600);
$cache_data = $memcache->get('key');
大概就是這樣啦! 簡單方便好用阿! :D
不過目前我的一些東西都會用到同一台 memcache server, 所以至少每個網站都得要各自的 key prefix, 才不會衝到, 所以寫了一個給 CodeIgniter 用的 mcache library, 基本上就是個 wrapper, 除了處理 key prefix, 連線, 還有把設定給寫到 config 檔, 可以直接修改 config 檔來設定 memcache, 跟 prefix。
key prefix 處理大概像是這樣, 而 prefix 就是在 config 做設定了:
public function get($key)
{
if (!$this->status) return;
return $this->memcache->get($this->prefix . '_' . $key);
}
public function set($key, $value, $compressed = null, $expire = null)
{
if (!$this->status) return;
if (!isset($compressed))
$compressed = $this->compressed;
if (!isset($expire))
$expire = $this->expire;
$this->memcache->set($this->prefix . '_' . $key, $value, $compressed, $expire);
}
而設定檔像是這樣:
$config['memcache_host'] = '127.0.0.1';
$config['memcache_port'] = 11211;
$config['memcache_prefix'] = 'stickeraction';
$config['memcache_compressed'] = MEMCACHE_COMPRESSED;
$config['memcache_expire'] = 60*5;
$config['memcache_pconnect'] = false;
目前用來處理 stickeraction 貼紙的部份, 大概從 0.01s 降到 0.003s 吧? 其實沒認真測 XD
另外, 可以用 memcache 的 getStats 函式寫一個來看 memcache 的使用情形
$memcache = new Memcache;
$memcache->connect('127.0.0.1', 11211);
$stats = $memcache->getStats();
foreach ($stats as $key => $val) {
echo "$key : $val <br />";
}
在 PHP Manual 的這裡可以看到相對應的欄位說明, 如下:
pid Process id of this server process uptime Number of seconds this server has been running time Current UNIX time according to the server version Version string of this server rusage_user Accumulated user time for this process rusage_system Accumulated system time for this process curr_items Current number of items stored by the server total_items Total number of items stored by this server ever since it started bytes Current number of bytes used by this server to store items curr_connections Number of open connections total_connections Total number of connections opened since the server started running connection_structures Number of connection structures allocated by the server cmd_get Cumulative number of retrieval requests cmd_set Cumulative number of storage requests get_hits Number of keys that have been requested and found present get_misses Number of items that have been requested and not found bytes_read Total number of bytes read by this server from network bytes_written Total number of bytes sent by this server to network limit_maxbytes Number of bytes this server is allowed to use for storage.
memcache 真的是簡單又好用阿! :D
身體不適的狀況越來越嚴重, 我的肩膀跟脖子都有嚴重石化的傾向, 甚至在公司午休時無法趴睡, 而我的左手也幾乎無法出力。 每天起床的時候, 肩膀跟脖子痛的要死, 我也不清楚為何是在起床的時候特別痛。 而在睡覺時, 也會因為肩膀跟脖子的疼痛而睡不著。
至於醒著的時候, 則是維持著基本的疼痛感, 可能由於這個疼痛的情形已經持續了快兩年, 我似乎是因為已經習慣了這個疼痛的感覺, 而視為理所當然。
今年年初也去看過復健科, 去看過整骨… 等等, 不過好像也沒什麼用。甚至在做過復健的電療後, 脖子突出了一塊, 到現在都沒有消去。 也許就是電腦打太久, 工作環境不良, 沒有運動 … 等, 所以後來也開始斷斷續續的跑步, 只是狀況也沒有太大的好轉, 有時甚至更劇烈疼痛。
不過一直到這半年來, 肩膀跟脖子疼痛越來越劇烈, 而且異常僵硬, 已經到了我需要以石化來稱呼。 其實一直在想, 到底是什麼原因造成的? 什麼時候開始的? 似乎就是在開始工作後的幾個月, 脖子開始覺得僵硬、疼痛。 一直持續到現在, 快兩年了, 其實我真的是滿會忍痛的。
以前有過某個經驗, 因為牙齒有問題, 連帶影響到脖子的某條神經之類的, 牙齒治療好之後, 脖子的疼痛也不藥而癒。 所以在肩膀脖子剛開始疼痛的時候, 我想說可能會是類似原因, 就跑去看了牙醫, 只是這個疼痛依舊。 (攤手)
一直在想著自己的身體怎麼會這樣, 一直到今年年初, 我開始覺得是因為工作環境問題, 可能桌椅不合人體工學? 當時在請假準備去看醫生的時候說出這個可能性猜測, 經理笑著說: 「那其他人怎麼不會?」 我也說不出個所以然來, 只笑著回答說:「我也不知道 :p」
慢慢的, 我開始觀察, 疼痛的加重情況就有如一個循環。 從禮拜一上班開始就慢慢加重, 一直到禮拜六開始減緩, 但隨著上班的開始, 又開始加重。 所以我只能猜測是工作的桌椅問題。 不過公司每個人都用同樣的桌椅, 為何只有我會這樣? 看來是我坐姿非常的不良? 又或者是我的風水特別不好? 或者是也許剛好我跟這個桌椅不合吧!?
我也不知道為何在家裡就不會有這種不舒服情況。 (攤手)
幾個禮拜前, 在做推拿的姑姑, 看了一下我的狀況, 他說我的左邊肩膀已經移位了, 一整個往上移, 連帶的影響到了我的左手, 導致左手無法施力。 姑姑說還滿嚴重的, 所以就幫我把身體橋了一下(其實是橋很久, 讓我痛的幾乎無法呼吸), 這才稍微減輕這惱人的疼痛感。
目前最近的狀況是, 上班時, 手靠在桌上想要打電腦, 肩膀、脖子就會痛, 只是可能習慣了, 就繼續打字、工作著, 然後到了下午, 疼痛感慢慢的增加。 然而最近疼痛越來越嚴重, 痛到我快要無法忍受, 也無法專心寫程式, 心情極度煩躁。
我只能說, 我的手快廢了, 脖子肩膀快不能動了, 我深覺得我不能再這樣繼續下去了。

這一兩天 twitter 非常不穩, 應該很多人發現自己已經 twitter 成癮了吧!? XD