|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-09-07 15:50 UTC] jimmycnw at gmail dot com
[2008-09-07 17:43 UTC] jani@php.net
[2008-09-15 01:00 UTC] php-bugs at lists dot php dot net
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 09:00:01 2025 UTC |
Description: ------------ The code is attached. Try executing 'SAVING' first. It will create a file 'temp.txt' approximately 450Kb in size. Then execute 'LOADING'. You will see, that over 3.5Mb (!!) of memory used in unserialize() function, while there are just 450Kb of data. Is it a bug in PHP? Any suggestions on how to fix it? (When I do the same with string, not array, everything works fine. The problem appears only when I use nested arrays) Reproduce code: --------------- define ('FILENAME', 'temp.txt'); define ('SIZE', 10 * 1024); // SAVING $array = array (); for ($i = 0; $i<SIZE; $i++) $array[] = array (uniqid ($i) => array ()); $data = serialize ($array); file_put_contents (FILENAME, $data); // LOADING $before = memory_get_usage (); $array = unserialize (file_get_contents (FILENAME)); $after = memory_get_usage (); echo 'Memory used: '.($after-$before).' bytes, while size of data: '.strlen (serialize ($array)); Expected result: ---------------- Memory used should be around 450Kb, while I see 3.5Mb. Actual result: -------------- Memory used: 3.5Mb