Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: Alb0 on September 19, 2014, 06:41:19 PM

Title: Need some assistance on PHP error
Post by: Alb0 on September 19, 2014, 06:41:19 PM
Hello friends,

I'm receiving some strange errors on my PHP module that parses XML feeds of my game server to display certain data on the forums. It only happens randomly at times, not sure why. I did not write the code, as I had someone else do so. Here's the errors I'm receiving; (I've also attached an image that displays the error code.)

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in /usr/www/clerks/public/forums/Sources/Subs-DreamModules.php(98) : eval()'d code:40 Stack trace: #0 /usr/www/clerks/public/forums/Sources/Subs-DreamModules.php(98) : eval()'d code(40): SimpleXMLElement->__construct('') #1 /usr/www/clerks/public/forums/Sources/Subs-DreamModules.php(98): eval() #2 /usr/www/clerks/public/forums/Sources/DreamPortal.php(437): dreamportal_code_content('// Servers to s...', 'PHP', false, Array, Array) #3 [internal function]: dreamPages() #4 /usr/www/clerks/public/forums/index.php(164): call_user_func('dreamPages') #5 {main} thrown in /usr/www/clerks/public/forums/Sources/Subs-DreamModules.php(98) : eval()'d code on line 40
Any help on this would be greatly appreciated!
Title: Re: Need some assistance on PHP error
Post by: Burke ♞ Knight on September 19, 2014, 06:42:22 PM
http://www.simplemachines.org/community/index.php?topic=527981.0;topicseen

Please do not post duplicate topics.
Title: Re: Need some assistance on PHP error
Post by: Alb0 on September 19, 2014, 06:43:42 PM
Quote from: BurkeKnight on September 19, 2014, 06:42:22 PM
http://www.simplemachines.org/community/index.php?topic=527981.0;topicseen

Please do not post duplicate topics.

It wasn't a duplicate, I realized it was in the wrong section. I've asked for the other one to be trashed, thus why I made another topic in this section. My apologies
Title: Re: Need some assistance on PHP error
Post by: Burke ♞ Knight on September 19, 2014, 06:57:35 PM
Well, here, they are great at moving topics, when asked. :)

For mod Related Questions it is best to ask the mod author. You can find a link to a topic for the mod or a support board on the mod's page in the Mod Site (http://custom.simplemachines.org/mods/)

This may be an issue with the portal's module...
Title: Re: Need some assistance on PHP error
Post by: Arantor on September 19, 2014, 08:09:58 PM
The error is telling you that the XML it's receiving is invalid. I can't obviously see why that would be; the XML looks legal to me.
Title: Re: Need some assistance on PHP error
Post by: Alb0 on September 19, 2014, 09:06:14 PM
That's strange, as the error only comes up every so often. I didn't code it myself, so I know very little about it to be honest, as my knowledge for it is kind of non-existent.
Title: Re: Need some assistance on PHP error
Post by: Arantor on September 19, 2014, 09:14:03 PM
Suggestion: replace the offending code with something that logs what's going on.

$xml = new SimpleXMLElement($data);
$xml = get_object_vars($xml);


try
{
$xml = new SimpleXMLElement($data);
$xml = get_object_vars($xml);
}
catch (Exception $e)
{
trigger_error('Invalid XML returned: ' . $data);
return;
}


Then when it happens you should get an error thrown into the log (and a non-fatal one since this is a caught exception not an uncaught one)
Title: Re: Need some assistance on PHP error
Post by: Alb0 on September 19, 2014, 09:21:00 PM
Receiving the following error when I input that code,

Parse Error: unexpected 'catch' (T_CATCH) on line 43
Title: Re: Need some assistance on PHP error
Post by: Arantor on September 19, 2014, 09:28:00 PM
Then I don't know what you've done. That's the correct syntax for a try/catch block.
Title: Re: Need some assistance on PHP error
Post by: Alb0 on September 19, 2014, 09:35:43 PM
Quote from: Arantor on September 19, 2014, 09:28:00 PM
Then I don't know what you've done. That's the correct syntax for a try/catch block.

Whoops, my mistake, I had made a minor error. All's working fine. Though I'd have to wait until the next time it acts up to receive any errors, which will most likely be in a few or a while.
Title: Re: Need some assistance on PHP error
Post by: Arantor on September 19, 2014, 09:41:12 PM
Cool. Lemme know what happens, am curious about this.