I'm starting to develop a web application in PHP that I hope will become incredibly popular and make me famous and rich. :-)
If that time comes, my decision whether to parse the API's data as XML with SimpleXML or to use json_decode could make a difference in the app's scalability.
Does anyone know which of these approaches is more efficient for the server?
**Update:** I ran a rudimentary test to see which method was more performant. It appears that `json_decode` is slightly faster executing than `simplexml_load_string`. This isn't terribly conclusive because it doesn't test things like the scalability of concurrent processes. My conclusion is that I will go with SimpleXML for the time being because of its support for XPath expressions.
XML elapsed: =sprintf('%.4f', ($end_xml - $start_xml))?>
JSON elapsed: =sprintf('%.4f', ($end_json - $start_json))?>
Result:
XML elapsed: 9.9836
JSON elapsed: 8.3606
Your benchmark isn't terribly realistic. Surely, you'll be manipulating the data in some way, not just loading it? At least try iterating through a few values or something. Load time probably isn't even the bulk of the actual processing you'll end up doing.以上就是What puts less load on a PHP server: SimpleXML or json_decode?的详细内容,更多请关注web前端其它相关文章!