PHP: XML file to string which is faster file_get_contents or simplexml_load_file with asXML()

主宰稳场 提交于 2019-12-04 06:33:36
readfile($filename);

file_get_contents/echo first reads the entire contents into the php process' memory and then sends it to the output stream. It's not necessary to have the entire content in memory if all you want to do id to forward it.
simplexml_load_file() not only reads the entire content into memory, it also parses the document which takes additional time. Again unnecessary if you don't want to get specific data from the document or test/modify it.

readfile() sends the content directly to the output stream and can do so "any way it see's fit". I.e. if supported in can use memory mapped files, if not it can at least read the contents in smaller chunks.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!