2016-07-29 56 views
0

我想將bigML模型對象存儲在memcache中。遵循以下步驟。Google應用引擎序列化問題

1-連載一個bigML模型對象

2-商店在內存緩存序列化字符串。

3-從memcache中獲取序列化字符串。

4-反序列化字符串。

$local_model = new Model($latestModel, $api); 
$local_model_obj = serialize($local_model); 
$memcache->set('latest_model_object',$local_model_obj); 
$local_model = unserialize($local_model_obj); 

注意:序列化和反序列化在我的本地服務器上正常工作。並在服務器中,它是拋出低於錯誤。

反序列化():錯誤偏移量100 3726的字節/鹼..

截圖:http://prnt.sc/byzzai

enter image description here

+1

請不要將文字發佈爲圖片。將它們複製粘貼到您的帖子中。 –

+0

將對象直接放入memcache會自動將它們串行化......試試? – Tom

回答

0

Vaishnavesh,

這可能是與不同​​的編碼的問題本地服務器和遠程服務器之間的版本。無論如何,嘗試檢查是否使用base64編碼幫助:

$local_model_obj = base64_encode(serialize($local_model)); 
... 
$local_model = unserialize(base64_decode($local_model_obj)); 

檢查這個其他答案:Change serialization functions in PHP for Memcached

+0

我試過一樣,但它不工作。 – Vaishnavesh

0
$local_model_obj = serialize($local_model); 
$specialChar = before ('ass"', after ('";O:8:"', $local_model_obj)); 
$local_model_obj = str_replace($specialChar, 'stdCl', $local_model_obj); 
$local_model = unserialize($local_model_obj); 

function after ($this, $inthat) 
{ 
    if (!is_bool(strpos($inthat, $this))) 
    return substr($inthat, strpos($inthat,$this)+strlen($this)); 
}; 
function before ($this, $inthat) 
{ 
    return substr($inthat, 0, strpos($inthat, $this)); 
}; 

這是工作的罰款。但我認爲這不是一個有效的方法。