# serialize() is slow

- Thread: https://externals.io/message/8773
- Original archive: https://news-web.php.net/php.internals/8773
- Started by Wez Furlong on 2004-03-26T14:38:26+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #8773 — Wez Furlong — 2004-03-26T14:38:26+00:00

URL: https://externals.io/message/8773#8773

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.
