XMLWriter output file truncated?
Posted: Wed Sep 03, 2008 9:07 am
Hi,
I'm having a strange problem that I can't figure out. I'm trying to generate a large XML file using XMLWriter but the file I generate never grows beyond 3138986 bytes (whether I use the XMLWriter to write to a file/URI or generate the XML in memory and then pass it though gzwrite() doesn't affect the outcome; the (gunzipped) file never grows beyond 3138986 bytes.
Here's some code excepts of what I'm doing:
In summary, no matter what I do, I can't seem to generate an XML file greater than 3138986 bytes. I've tried flushing the buffer after every DB fetch (if writing to a non-compressed file) but nothing helped. I'm not running into any (visible) PHP memory or processing time limits.
Any ideas would be much appreciated.
Thanks
Rob
I'm having a strange problem that I can't figure out. I'm trying to generate a large XML file using XMLWriter but the file I generate never grows beyond 3138986 bytes (whether I use the XMLWriter to write to a file/URI or generate the XML in memory and then pass it though gzwrite() doesn't affect the outcome; the (gunzipped) file never grows beyond 3138986 bytes.
Here's some code excepts of what I'm doing:
Code: Select all
$writer = new XMLWriter();
if ($this->_gzip) {
$writer->openMemory();
$fp = gzopen ($this->_filename.'.gz', 'wb');
} else {
$writer->openURI($this->_filename);
}
$writer->startDocument('1.0', 'ISO-8859-15');
$writer->setIndent(4);
$writer->startElement('Products');
$count = 0;
$page = 0;
$objArray = new PNProductArray ();
$colArray = getColumnsArray('table');
do {
$data = selectFromDB ('$page*$this->_pagesize, $this->_pagesize);
foreach ($data as $dat) {
$writer->startElement('Product');
foreach ($colArray as $field) {
$writer->writeElement($field, $dat[$field]);
}
$writer->endElement();
$count++;
}
$page++;
} while ($data);
$writer->endElement();
$writer->endDocument();
if ($this->_gzip) {
$xml = $writer->outputMemory();
$fp = gzopen ($this->_filename.'.gz', 'wb');
gzwrite ($fp, $xml);
gzclose ($fp);
} else {
$writer->flush();
}
Any ideas would be much appreciated.
Thanks
Rob