Preferred method to store PHP arrays (json_encode vs serialize)

前端 未结 20 2179
孤独总比滥情好
孤独总比滥情好 2020-11-22 05:55

I need to store a multi-dimensional associative array of data in a flat file for caching purposes. I might occasionally come across the need to convert it to JSON for use in

20条回答
  •  Happy的楠姐
    2020-11-22 06:35

    THX - for this benchmark code:

    My results on array I use for configuration are as fallows: JSON encoded in 0.0031511783599854 seconds
    PHP serialized in 0.0037961006164551 seconds
    json_encode() was roughly 20.47% faster than serialize() JSON encoded in 0.0070841312408447 seconds
    PHP serialized in 0.0035839080810547 seconds
    unserialize() was roughly 97.66% faster than json_encode()

    So - test it on your own data.

提交回复
热议问题