PHP: Serializing data to save it for caching
I need to cache some data to disk between PHP requests so I decided to compare the various methods available.
Using 100000 element array as source data
Serialize save: 2.958 ms (1.5M)
Serialize read: 5.447 msJSON save: 1.880 ms (574.96K)
JSON read: 6.876 msPHP save: 8.684 ms (1.7M)
PHP read: 26.863 msMemcache set: 5.651 ms
Memcache get: 2.465 msIGBinary save: 1.377 ms (720.08K)
IGBinary read: 2.245 msMsgPack save: 1.389 ms (359.92K)
MsgPack read: 2.930 ms
I was surprised to see IGBinary and MsgPack so much faster than native JSON. JSON is easy and super portable, but not the fastest.