iT邦幫忙

0

php memcached 無法使用

我有testMemcached.php程式碼在下面.

<?php
include_once "common.php";
include_once "api.php";
class TestMemcached extends API{
    function impl(){
         $m = $this->getMem();
         $stats = $m->getStats();
         var_dump($stats);

        $m->add("Key","test");
        echo "Value:".$m->get("Key");
    }
}
$api = new TestMemcached();
$api->go();

我在瀏覽器執行 testMemcached.php . 我得到 bool(false) Value:.
我已在phpinfo.php和使用service memcached status確認memached有安裝和啟動

我的系統環境:CentOS 7. LNMP.

我使用 telnet 127.0.0.1 11211 去測試 memcached 功能
我發現 addset 無法正常執行

Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
set test testValue
ERROR
add test testValue 
ERROR
get test
END

請問如何處理這問題?

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
wiseguy
iT邦超人 1 級 ‧ 2018-05-23 16:41:41

不懂你為什麼安裝了 php 的 memcached,卻用 telnet 在試?!memcached 的 protocol 跟 telnet 一樣嗎?要試也是寫 php 去試 get/set 吧?

yayaigo iT邦新手 5 級 ‧ 2018-05-23 17:21:11 檢舉

用php 的add 和 get 在文章中的code就試過了.
造道理telnet的測試結果,也應該要正常執行,
但卻不行似乎跟php沒關係,memcached的設定不知道哪裡有問題
Any other idea?

wiseguy iT邦超人 1 級 ‧ 2018-05-25 14:00:42 檢舉

如果你是只要試 telnet command,那命令後應該加 \r\n 做為命令結尾。

yayaigo iT邦新手 5 級 ‧ 2018-05-25 16:41:52 檢舉

不用吧. 按Enter按鈕,就是\r\n

我要發表回答

立即登入回答