Re: [PHP] domxml_load_mem()/_file()

2005-07-02 Thread Jochem Maas

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



[PHP] domxml_load_mem()/_file()

2005-06-29 Thread Chris Boget
Is there a hard limit to the size of the file you can load into the DOM
using either of the above functions?  I ask because I have a 5mb XML
file I'm trying to load and both functions die when used.  I've whittled
the size down to about 1.5mb and both functions then work.  It's not
as if it's dying because the structure of the XML is invalid, since I am
not altering the structure as I whittle it down.  When my script runs, I
can't check for any possible errors because the script dies *at*/*in* the
load function.  
The nearest I can tell is that it's dieing because of memory issues.
That for some reason, the size is too large for PHP to load into the
DOM.  When I load the file into XMLSpy, that applications mem usage
in task manager (WinXP) is showing as 150k and my system bogs
down alot.  But even so, XMLSpy is loading it.  The server that I am
running my script on (only to die) is Windows 2003 running Apache
2 and has 1GB of RAM.  And though I'll grant you that the server is
also running the likes of IIS, SQL Server and a few other intensive
applications, 1GB should be more than enough.
So I'm wondering if there might be some other reason, apart from the
memory, that such a large XML document would cause both of the
above named functions to cause the script to halt/crash.
 
thnx,
Chris


Re: [PHP] domxml_load_mem()/_file()

2005-06-29 Thread Chris Boget
 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
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