|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-05-05 14:57 UTC] iliaa@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 08:00:02 2025 UTC |
Description: ------------ I have a 73MB large xml file which will be parsed via command line with the following script. Reproduce code: --------------- set_time_limit(600); error_reporting(E_ALL); ini_set('memory_limit',-1); $ricxml2 = simplexml_load_file('path/to/file.xml'); $ricxml = xml2php($ricxml2); function xml2php($xml) { $fils = 0; $tab = false; $array = array(); foreach($xml->children() as $key => $value){ $child = xml2php($value); /* To deal with the attributes */ foreach($value->attributes() as $ak=>$av){ $child[$ak] = (string)$av; } /* Let see if the new child is not in the array */ if($tab==false && in_array($key,array_keys($array))){ /* If this element is already in the array we will create an indexed array */ $tmp = $array[$key]; $array[$key] = NULL; $array[$key][] = $tmp; $array[$key][] = $child; $tab = true; }elseif($tab == true){ /* Add an element in an existing array */ $array[$key][] = $child; }else{ /* Add a simple element */ $array[$key] = $child; } $fils++; } return $array; } Expected result: ---------------- just a converted xml structure .... it worked with files below 66 MB Actual result: -------------- the error occured in this line: in_array($key,array_keys($array)) Fatal error: Out of memory (allocated 217317376) (tried to allocate 16 bytes) in parse_ric_simplexml_initial.php5 on line 38 on the whole freebsd machine all other programms/servers are stopped so that 1.4 GB RAM is available for the script. last pid: 79586; load averages: 0.65, 0.26, 0.18 26 processes: 2 running, 24 sleeping CPU states: 42.2% user, 0.0% nice, 8.1% system, 0.0% interrupt, 49.7% idle Mem: 506M Active, 383M Inact, 204M Wired, 75M Cache, 112M Buf, 332M Free Swap: 3000M Total, 192K Used, 3000M Free PID USERNAME THR PRI NICE SIZE RES STATE C TIME WCPU COMMAND 79585 root 1 107 0 490M 487M CPU1 0 0:33 98.23% php5 513 root 1 96 0 3552K 1400K select 0 0:32 0.00% nmbd 434 root 1 96 0 3420K 2044K select 0 0:28 0.00% sendmail 37085 root 1 4 0 5440K 1836K sbwait 0 0:10 0.00% sshd