user1345414
user1345414

Reputation: 3865

Reduce processing time of saveXML

I use PHP and there are tow APPs.

One APP, named APP-1, handles over 800,000 rows of Oracle DB to XML document.

Another APP, named APP-2, that takes XML from APP-1 as http response and show the data as Web page.

Maximum data, APP-2 can request for APP-1 is 100,000 rows.

If APP-2 wants to get whole 800,000 rows APP-2 has to make request APP-1 for 8 times.

Now I run APP-2 and APP-1.

And APP-1 finished in 300 sec for processing all rows.

Now I want know how to reduce processing time.

APP-1 generates XML with saveXML. It takes 25 sec in average, 180 sec in total. It is nearly a half of whole processing time.

On the other hand APP-2 is much faster than APP-1.

APP-2 parses XML with simplexml_load_string and changes into HTML. It takes 5sec in average 35 sec in total.

I think 100,000 rows doesn’t key factor for processing time because simplexml_load_string is much faster than saveXML..

Is there any good solution to reduce processing time for the part saveXML does?

Upvotes: 1

Views: 176

Answers (1)

hek2mgl
hek2mgl

Reputation: 157957

Note, a DOM document will need relatively much memory, as the whole document tree must be held in memory. DOM is good for parsing and manipulating existing xml content. If you just need to output XML I would not suggest to use a document for it. Just plain string output would fit most. Like this:

echo '<?xml version="1.0"?>';
echo '<data>';
while($row = $result->fetchRecord()) {
    echo '<row>
            <foo><![CDATA[' . $ow['foo'] . ']]></foo>
            <bar><![CDATA[' . $row['bar'] . ']]></bar>
          </row>';
}
echo '</data>';

You could increase that performance using output buffering:

ob_start(4096); // start buffering of output using a 4096 bytes sized buffer

echo '<?xml version="1.0"?>';
echo '<data>';
while($row = $result->fetchRecord()) {
    echo '<row>
            <foo><![CDATA[' . $ow['foo'] . ']]></foo>
            <bar><![CDATA[' . $row['bar'] . ']]></bar>
          </row>';
}
echo '</data>';

ob_end_flush();

Note if your content from database might containt content like ]]> (what would close the CDATA sections, it must be escaped before using. This is especially the case if you have binary data.

Upvotes: 2

Related Questions