I don't get it, the data produced by json_encode
is much more straightforward than serialize
and yet both the JSON encode and decode functions are much more slower than the serialize
and unserialize
counterparts. Why?
Asked
Active
Viewed 6,233 times
6
-
7in which way is JSON much more straightforward then php-native serialize, when you see it from the point of view of a computer. I think JSON more straightforward, but only for humans. – TheHippo Dec 14 '09 at 12:29
-
2See also http://stackoverflow.com/questions/804045/preferred-method-to-store-php-arrays-json-encode-vs-serialize – David d C e Freitas May 04 '11 at 23:16
-
@David: Yes, I'm aware, thanks! ;) – Alix Axel May 04 '11 at 23:47
1 Answers
14
json_encode
does string parsing and tons of allocs compared to serialize
's memcpy
Have fun in the source if you're really in the mood.

tristanbailey
- 4,427
- 1
- 26
- 30

Paul Tarjan
- 48,968
- 59
- 172
- 213
-
-
Looks like the source for [json_encode](https://github.com/php/php-src/blob/master/ext/json/json_encoder.c) vs [serialize](https://github.com/php/php-src/blob/master/ext/standard/var.c) Looks tidy code but I can't read C well ! – tristanbailey Feb 13 '21 at 14:10