When using mc, we will consider the data storage format. The PHP function allows us to directly set an array to MC. After obtaining it, we can also use it as an array, which is really simple, however, after comparison with the JSON format, we found that the simple cost is a waste of more space. Below is a small test program:
<? PHP
$ Host = "10.10.10.10 ";
$ Port = "11211 ";
$ Uid = "103630 ";
$ P1 = array (
"ET" => "103630", // expire time
"PT" => "103630 ",//
"PV" = & gt; "103630 ",
"Ut" = & gt; "103630 ",
"St" => "103630 ",
"PP" => "103630 ",
"S" => "103630 ",
"OT" => "103630"
);
$ Data [] = $ P1;
$ MC = new memcache ();
$ Mc-> connect ($ host, $ port );
$ Mc-> set (103631, $ data );
$ Mc-> set (103632, json_encode ($ data ));
?>
Telnet 10.10.10.10 11211
Get 103631
Value 103631 1 191
A: 1: {I: 0; A: 8: {s: 2: "ET"; s: 6: "103630"; s: 2: "PT"; s: 6: "103630"; s: 2: "PV"; s: 6: "103630"; s: 2: "ut"; s: 6: "103630"; s: 2: "St"; s: 6: "103630"; s: 2: "PP"; s: 6: "103630"; s: 1: "S"; s: 6: "103630"; s: 2: "OT"; s: 6: "103630 ";}}
End
Get 103632
Value 103632 0 114
[{"ET": "103630", "PT": "103630", "PV": "103630", "ut": "103630", "St ": "103630", "PP": "103630", "S": "103630", "OT": "103630"}]
End
It can be seen that JSON still saves memory space.
However, PHP can serialize all types except the resource type. JSON can only be serialized in four ways, and the expression is very concise.