开发者

why is new SimpleXMLElement($tags) causing my php script to crash;

开发者 https://www.devze.com 2023-02-07 01:54 出处:网络
I am trying to run some client code to call a server side API. I put various put statements to see where the code crashes and the line crashing it is

I am trying to run some client code to call a server side API. I put various put statements to see where the code crashes and the line crashing it is

$tagXml = new SimpleXMLElement($tags);

(where tags is the result of a file_get_contents call)

I downloaded php5 and I am running it from the php source file from the command line.

Why is this crashing the code. Perhaps there is an addon for php I need to add to use new SimpleXMLElement($param)

edit I got error reporting working Warning: simplexml_load_file(): I/O warning : failed to load external entity "h开发者_开发百科ttps://api.domain/v2/andy/tags" in C:\java\domain-api-v2\simple\list- tags.php on line 30 working line 30 Fatal error: Uncaught exception 'Exception' with message 'String could not be pa rsed as XML' in C:\java\domain-api-v2\simple\list-tags.php:37 Stack trace:

0 C:\java\domain-api-v2\simple\list-tags.php(37): SimpleXMLElement->__const

ruct('')

1 {main}

thrown in C:\java\domain-api-v2\simple\list-tags.php on line 37


I would check your error log. There are two immediate possibilities:

  • You are not including the SimpleXMLElement class in the file that you are running
  • $tags is some kind of format that SimpleXMLElement doesn't like.

If you check your error log (and have error reporting turned on) then you should see whats going on.


I was experienced this problem before. How much size of $tags contents ?

You have to use simplexml_load_file() instead of file_get_contents() , if file's size are bigger and server performance is low.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号