Re: domxml_load_mem()/_file()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Chris Boget wrote:
If it's because of memory issues then it will indicated by an error
message saying that your script has tried to allocate more than the
allowed memory limit (and it's easy to fix by adjusting this limit in
php.ini)


Actually, I'm not getting any error at all.  The script just halts.  I am
only guess that it's a memory issue because the file is so large and
because when I shrink the file down, everything works.
After alot of additional testing, it turns out the problem isn't with the
domxml_load_*() functions after all.  My apologies.  Although my
script is still halting inexplicably, it seems that the root cause of that
is a function I'm using to turn the DOM into an array.  The function
that I am using is one that I snagged from the user contributed notes
for the xml_tree() function and can be found here:

http://us2.php.net/manual/de/function.domxml-xmltree.php#25964

I still believe it to be a memory issue but for the life of me, can't figure out how I can rework the domxml_xmlarray() exampled in
the above link such that it uses the domxml nodes by reference

it all starts with the '&' char. below is an attempt, not tested,
basically everywhere I see that its possible to use
a reference I did (I may be wrong), I wasn't sure about the
array_merge() line so you will have to test that.

I removed an if statement which seemed superfluous and slightly
wrong (i.e. if $branch =& $branch->next_sibling() returns null what will the
subsequent call to $branch->first_child() do??)

Also the function does not return by reference (you may want it
to), I though it might cause problems with data changing
for 'unknown' reasons.

Also depending on your php version you may run into the
'call-time-pass-by-reference' depreciated warning. -- if you
change the array_merge() line to use references for the passed args:

   function domxml_xmlarray(&$branch) {
       $object = array();
       $objptr =& $object;
       $branch =& $branch->first_child();

       while ($branch && !$branch->is_blank_node()) {
               switch ($branch->node_type()) {
                   case XML_TEXT_NODE:
                       $objptr['cdata'] =& $branch->node_value();

                       break;
                   case XML_ELEMENT_NODE:
                       $objptr =& $object[$branch->node_name()][];

                       break;
               }

               if ($branch->has_child_nodes()) {
		   // not sure about referenced args to this function.
                   // $objptr =& array_merge(&$objptr, &domxml_xmlarray($branch));
                   $objptr =& array_merge($objptr, domxml_xmlarray($branch));
               }

               $branch =& $branch->next_sibling();
       }

       return $object;
   }

let us know how you get on. if it works well it would be nice to post
it back to the usernotes as an improved version (go right ahead and take credit,
I figure you'll probably have spent enough time/effort getting it to work :-)

and not by value and thus compounding the memory usage. Do
any of you guys have any ideas?  Do any of you use a similar
function that isn't as memory intensive?

thnx,
Chris


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux