Send empty packets to not timeout the connection
<p>Real world problem: I'm generating a page dinamically. This page is an xml which is retrieved by the user (curl, file_get_contents or whatever can by made server side scripting).
Once the user make the request, he start waiting and I start retrieving a large set of data from the db and building an xml with them (using the php dom objects). Once I've done I fire the "print $document->saveXML()". It takes about 8 minutes to create this 40 megabytes document. Then as it is ready I serve the page/document. Now I have a user who has a 60 seconds connection timeout: he said I need to send the first octet each 60 seconds. How can I achieve such a thing? </p>

<p>Since it's useless to post a 23987452 lines code cause nobody is gonna read them, I'll explain the script which serves this page as real-very-pseudo-pseudo-code:</p>

<ul>
<li>grab all the data from the db: an enormous set of rows</li>
<li>create a domdocument element</li>
<li>loop through each row and add a node element to the domdocument to contain a piece of data</li>
<li>call the $dom->saveXML() to get the document as a string</li>
<li>print the string so the user retrieve an xml document</li>
</ul>

<p>1) I can't send real data since it is an xml document and it has to begin with <code>"&lt;?xml..."</code> to not mess up the parser.`</p>

<p>2) The user can't deal with firewall/serverconfig</p>

<p>3) I can't deal with "buy a more powerful server"</p>

<p>4) I tried using an ob_start() at the top of the script and then at the beginning of each loop a <code>"header("Transfer-Encoding: chunked"); ob_flush(); "</code> 
but nothing: nothing comes before the 8 minutes.</p>

<p>Help me guys!!</p>
