我有两台服务器
服务器A使用读取http://www.some-url.com/xmlwriter_src.php
$reader = new XMLReader();
$reader->open('http://www.some-url.com/xmlwriter_src.php');
while ($reader->read())
{
/* -- do something -- */
}
服务器B创建一个xml流
$writer = new XMLWriter();
$writer->openURI('php://output');
$writer->startDocument("1.0");
$writer->startElement("records");
while(!$recordset->EOF)
{
$writer->startElement($fieldname)
$writer->text($recordset->fields[$fieldname]);
$writer->endElement();
$recordset->movenext();
}
服务器A上的xmlreader一直在抱怨服务器B没有响应,即使我可以在浏览器中看到xml结果.
生成需要不到一秒的时间
如果我将xml复制到静态文件,xmlreader将输出该文件.
解决方法:
默认情况下,写入器将缓冲输出.
一旦完成,你必须调用flush().
$writer = new XMLWriter();
$writer->openURI('php://output');
$writer->startDocument("1.0");
$writer->startElement("records");
while(!$recordset->EOF)
{
$writer->startElement($fieldname)
$writer->text($recordset->fields[$fieldname]);
$writer->endElement();
$recordset->movenext();
}
$writer->flush();
顺便说说:
你在哪里关闭记录元素?