我想與我的rails和php服務器共享我的memcache服務器。Memcache與rails和php
滑軌:
my_var = {'one'=>1,'two'=>2}
Rails.cache.write 'hello', PHP.serialize(my_var), :raw => true
Rails.cache.read 'hello'
輸出:
"a:2:{s:3:\"one\";i:1;s:3:\"two\";i:2;}"
PHP:
$var = self::$memcache->get('hello');
die(var_dump($var));
輸出:
"a:2:{s:3:\"one\";i:1;s:3:\"two\";i:2;}"
PHP.serialize是一個來自gem php_serialize的函數。 我希望我的PHP服務器可以提取hello並生成一個數組。任何人都可以幫助我,我在這裏做錯了哪一部分?
謝謝
謝謝。它像你說的那樣工作。事情是,我的PHP是一個遺留代碼,我試圖不改變任何東西。我希望我能從Rails方面開展一些工作。另一個問題是,在PHP代碼中,$ hello = array('one'=> 1,'two'=> 2); self :: $ memcache-> set('hello',$ hello,false,false); ('hello'); die(var_dump($ var));'code'將輸出'code'array(2){[「one」] => int(1) )[「two」] => int(2)}'code',但是從rails側:'code'Rails.cache.read('hello')'code'輸出'code'「a:2:{s: 4:\ 「薩圖馬雷\」; I:1; S:3:\ 「DUA \」; I:2;}「'code'。那麼爲什麼PHP在這裏反序列化呢? – Fajarmf
這可能與您的PHP類有關。你正在使用PHP類還是memcached擴展?如果您正在使用該類,請嘗試瞭解在調用set方法時它的作用。 – chiborg