Edit report at http://bugs.php.net/bug.php?id=51155&edit=1
ID: 51155
Comment by:
Reported by: flavius dot as at gmail dot com
Summary: serialize() crashes with unreasonable/unexplicable
"out of memory" for objects
Status: Feedback
Type: Bug
Package: SPL related
Operating System: ArchLinux x86_64
PHP Version: 5.3.1
New Comment:
Using it gives the configure error:
configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL
is missing. This should not happen. Check config.log for additional
information.
Previous Comments:
------------------------------------------------------------------------
[2010-03-01 17:02:22] [email protected]
Please try using this snapshot:
http://snaps.php.net/php5.3-latest.tar.gz
For Windows:
http://windows.php.net/snapshots/
------------------------------------------------------------------------
[2010-02-26 13:41:59] flavius dot as at gmail dot com
Oh and I've forgot to mention, there's plenty of RAM and swap space
before running php -f:
free -m
total used free shared buffers
cached
Mem: 1975 1732 243 0 131
1027
-/+ buffers/cache: 573 1402
Swap: 5718 0 5718
------------------------------------------------------------------------
[2010-02-26 13:38:28] flavius dot as at gmail dot com
Updated OS: ArchLinux x86_64
------------------------------------------------------------------------
[2010-02-26 13:35:13] flavius dot as at gmail dot com
Description:
------------
When serializing a SplFixedArray with serialize(), the script dies with
"Fatal error: Allowed memory size of 134217728 bytes exhausted"
The "expected result" works and allocates at most 20.96 mb for $cnt =
8565 on line 15.
The "actual result" crashes when serialize()'ing with $cnt only
incremented by one, which is not understandable.
The actual values may vary, but if you play enough with it you'll find
at which amount of items serialize() has that spark.
Then you can toggle to using plain arrays on line 17, and that problem
will disappear, although arrays actually consume more memory (in my
experiments around 1.2 mb more).
Reproduce code:
---------------
1 <?php
2 function rand_str($length = 32, $chars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz1234567890') {
3 $chars_length = (strlen($chars) - 1);
4 $string = $chars{rand(0, $chars_length)};
5 for ($i = 1; $i < $length; $i = strlen($string)) {
6 $r = $chars{rand(0, $chars_length)};
7 if ($r != $string{$i - 1}) $string .= $r;
8 }
9 return $string;
10 }
11 function convert($size) {
12 $units=array('b','kb','mb','gb','tb','pb');
13 return
@round($size/pow(1024,($unit=floor(log($size,1024)))),2).'
'.$units[$unit];
14 }
15 $cnt = 8566;
16 $r = new SplFixedArray($cnt);
17 //$r = array();
18 for($i=0;$i<$cnt;$i++) {
19 $r[$i] = rand_str(1024);
20 }
21 echo "\nGENERATING DONE\n";
22 echo 'peak before serialize()
',convert(memory_get_peak_usage()),PHP_EOL;
23 echo "---\n";
24 $r = serialize($r);
25 echo 'peak after dumping
',convert(memory_get_peak_usage()),PHP_EOL;
26 unset($r);
Expected result:
----------------
GENERATING DONE
peak before serialize() 10.19 mb
---
peak after dumping 20.96 mb
Actual result:
--------------
GENERATING DONE
peak before serialize() 10.19 mb
---
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to
allocate 8913127 bytes) in /home/flav/softpedia/bigarray-bugreport.php
on line 24
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=51155&edit=1