Home >Backend Development >PHP Tutorial > php的数据对象、构造的存储

php的数据对象、构造的存储

WBOY
WBOYOriginal
2016-06-13 13:03:44948browse

php的数据对象、结构的存储

1.使用序列化和反序列化函数,?然后将序列化结果$result存储到文件或者数据库中进行持久存储

$result = serialize($data);

?

$data = unserialize($result)?

?

2.使用分布式内存对象缓存系统 memcached

2.1安装memcached客户端 将数据存储在该客户端的内存中

win32版memcached?http://code.jellycan.com/memcached/

可安装为服务

?

memcached -d install

memcached -d start

?

2.2安装php扩展

下载?http://shikii.net/blog/downloads/php_memcache-cvs-20090703-5.3-VC6-x86.zip

编辑php.ini extension=php_memcache.dll

示例代码:

?

?

<?php $memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");

$version = $memcache->getVersion();
echo "Server's version: ".$version."<br>\n";

$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;

$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)<br>\n";

$get_result = $memcache->get('key');
echo "Data from the cache:<br>\n";

var_dump($get_result);

?>

?参考网址:http://shikii.net/blog/installing-memcached-for-php-5-3-on-windows-7/

?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn