serialize() is slow

php.internals

Wez Furlong

22 years ago
I don't normally go in for big arrays in PHP, but I've had the "opportunity" to write a script that grabs a couple of thousand rows from a database, each row having ~120 small fields, and serialize it for consumption elsewhere. I didn't benchmark it, but it takes a good few seconds to serialize. I can write my own serialization function in native php using foreach() and addcslashes etc. and have it run in ~1 second. That probably means that serialize() should be able to run in less time than that. Would one of the performance gurus mind taking a look at serialize? My gut feeling is that there are a lot of reallocs() going on, so it might simply be solved by setting a bigger chunk size (smart_str stuff). --Wez.