Skip to content

Instantly share code, notes, and snippets.

@kejyun
Created December 8, 2013 06:09
Show Gist options
  • Save kejyun/7853898 to your computer and use it in GitHub Desktop.
Save kejyun/7853898 to your computer and use it in GitHub Desktop.
php與node.js共享memcache資料
<?php
// 連線Memcache
$meminstance = new Memcache();
$meminstance->pconnect('localhost', 11211);
// 存放資料到Memcache
$cache_key = 'php_memcached_key';
$cache_data = array(
'name'=>'KeJyun',
'blog'=>'http://blog.kejyun.com'
);
// 編碼成JSON資料
$cache_data = json_encode($cache_data);
$meminstance->set($cache_key, $cache_data, 0, 600);
// 讀取Memcached存放的資料
$res = $meminstance->get($cache_key);
var_dump($res);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment