tags:

views:

69

answers:

2

Hello all,

I have found these errors in my error log:

[05-Aug-2009 12:57:27] PHP Warning:  SimpleXMLElement::__construct() [<a href='simplexmlelement.--construct'>simplexmlelement.--construct</a>]: ^ in /home/mojo/public_html/shackupload.php on line 37

The funny thing is I had about 200 of the above in my error log all with the same timestamp! What is going on and why so many?!

The lines in question is this:

if(!(substr($res, 0, 6)=='Failed')){

    $xml = new SimpleXMLElement($res) or die('Error creating a SimpleXML instance');
    $imagelink = (string) $xml->image_link; // This is the image link
    $_SESSION['shack_link'] = $imagelink;
    echo 'done'; 
}
+3  A: 

The documentation of SimpleXMLElement::__construct says (quoting) :

Errors/Exceptions

Produces an E_WARNING error message for each error found in the XML data and throws an exception if errors were detected.

So, I'd say you tried to load a file that contains XML errors (a non-valid file, for instance).

And to explain the fact you got 200 errors at the same time : you must have something like 200 errors in your file, as __construct generates one E_WARNING per error in the XML data.

Logging the XML data to a file, in such situation, might help you finding precisely what caused the warnings... At least if that doesn't happen often.


EDIT : BTW, looking at your error_log once in a while is really a good idea ! I don't see enough people doing that :-(

Pascal MARTIN
+1  A: 

Try echoing out $res before that block of code. It looks like your $res string contains a caret ^ at the beginning or somewhere outside of the markup.

Mark