tags:

views:

168

answers:

2

I am retrieving XML from a web service and then loading it into MiniXml (PHP). When the file is smaller than 100k it parses just fine. Larger, and I get an error:

Call to a member function getElement() on a non-object

This is happening when I try to get the first element off of the root element.

$parsedDoc = new MiniXMLDoc();
$parsedDoc->fromString($xml);
$root =& $parsedDoc->getElement('my-root-element');
$lists =& $root->getElement($type);

The web service that I call allows me to specify the number of top level elements to call. The last element that takes the size over 100k is well formed and does not have any issues at all. The only thing that I can think of is size. In this case, does size matter?

Update: I believe this is a buffer problem, but I don't know which buffer is causing the problem. I am sure it isn't the "web service call" because I know that it is retrieving all of the data. Is it a PHP buffer or a MiniXml buffer that is causing the issue? Or is it something else entirely? (Thanks Dan for pointing this out)

A: 

I know little about php and nothing about MiniXml, but what comes to mind is that maybe you've got an input buffer that's <= 100K in size, and so when it's fed into MiniXML, the close tag is missing from the top-level element in the document. (That would be a different issue from whether the last element which you cited, being well formed.)

Dan Breslau
This is exactly what I was thinking, but I don't know where the buffers are specified. Is it a PHP buffer? A MiniXml buffer? I will update my question. Thanks!
Sixty4Bit
PHP's memory limit is set to 16M by default I think.. 100kb shouldn't be any hassle as far as PHP is concerned.
nickf
+5  A: 

I came across this exact same thing that I talked about when converting HTML to PDF.

This bug describes the problem. PHP 5.2.x introduced a new parameter pcre.backtrack_limit, defaulting it to a value of 100,000. Basically any preg_* function will silently fail on strings larger than 100k since PHP 5.2. By the way, the bug mentioend remains open. Nothing has been done about this.

The limit is too low. If you have the option raise it to like 2,000,000 (or whatever you need). If that's not an option--which it might not be in a shared hosting environment--then you've got problems.

I really couldn't believe this one when I found it. Not only did this change break heaps of templating code (as many threads, bug reports and comments on all of the above will attest) but no error is raised (unless you happen to look at preg_last_error(), which let's face it, most people don't).

cletus
cletus, Thanks! This looks like it is the issue that I am having. I am on a shared host and running out of memory, so that is an issue I will have to work with the provider. Thanks again!
Sixty4Bit