NYCPHP Meetup

NYPHP.org

[nycphp-talk] Unserializing big objects

Dan Cech dcech at phpwerx.net
Fri Feb 13 10:26:43 EST 2004


> I have flat files with serialized generic objects that are quite large --
> over 100k. These flat files are written as PHP scripts like so:
> 
> <?php 
> 
> $foo = 'O:8:"stdClass":23:{s:2:"id";s:1:"2";s:5:"email";s:17:"email ...
>  
> ... 100 kb of serialized data ...
> 
> ?>
> 
> Once included I try to unserialize $foo and it doesn't work. Strangely, it
> gives no error either. It works for shorter amounts of data, but there
> appears to be a limit.
> 
> Is this a limit of unserialize or include?

Hmmm, this does sound somewhat odd, I found a few reports of people 
using it on data ranging into megabytes without problems.  What version 
of PHP are you using?

Personally I would be looking at a more efficient form of storage for 
the data which would sidestep the problem you are experiencing.

> Since all the data is on one very long line, I tried chunk_split but
> unserialize doesn't like the new line characters being inserted into the
> data.

Yeah, serialized data needs to be read as one chunk, you can't just 
split it and read it piece-by-piece.

If you mail me the code that produces the error off-list (zipped 
please!) I'd be glad to check it out for you.

Dan




More information about the talk mailing list