How can I optimize my xml output so that the data transfer time be lower?
HI,
I have a cron that calls a basic API URL. The output is xml so I use php's file_get_contents()
to get the data to process.
My question is, Does the output format of the xml make a difference in the transfer time from one server to another? The cron is running every ten minutes and I don't want the crons to overlap at some point because the data processing is time sensitive.
ex :
<?xml version="1.0"?><api><data>sometext here</data></api><!-- As one line -->
<?xml version="1.0"?>
<api>
<data>sometext here<开发者_如何转开发;/data>
</api> <!-- As multiple lines -->
Note that this is only an xml example, the data of mine makes the xml output 2000+ lines long.
I have tested it and it seems like it is the same(maybe microseconds apart) for any type of xml. Is there any way of speeding that up?
If you don't cut your XML output Length itself i don't see a possebility for a big speedup.
Stripping unnecessary whitespaces for transport is pretty usefull because it could reduce transport speed. even if it is not that mutch. the longer your xml is and the more unnecessary whitespaces you have there (unnecessary for parsing the xml. only used for human readability) the more you will win. If you have a deep hirarchy and many white spaces to make it readable then you will gain mutch. If not then the stripping won't reduce transfer speed that mutch.
The only way i would see is to generate smaller xml data.
Maybe you could try a compression like gzip.
Compressed your pages using gzip. You can do this via mod_gzip (apache module) or if you are using PHP, set zlib.output_compression = On in php.ini. This will compress your plaintext content to ~20% of it's original size.
Also, if you are concerned about the absolute smallest possible data, instead of XML, you can send it out using JSON.
精彩评论