开发者

Server A using xmlreader to read XML from xmlwriter on server B

I have two servers

Server A reads http://www.some-url.com/xmlwriter_src.php using

$reader = new XMLReader();
$reader->open('http://www.some-url.com/xmlwriter_src.php');
while ($reader->read()) 
{
  /* -- do something -- */
}

Server B creates an xml stream

$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();
}

the xmlrea开发者_运维技巧der on server A keeps complaining that server B doesnt respond, even though I can see the xml result in the browser.

It takes less than a second to generate

If i copy the xml to a static file, the xmlreader outputs the file.


did u tried adding

header("Content-Type: text/xml");

Else the reader will consider it as simple text and wont work. Try giving that at the begining of the file.


By default the writter will buffer your output. Once you are done you MUST call 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();

By the way: where do you close the records element?


Try writing whatever xmlReader reads on the disk and inspect the generated file. I have a hunch its either empty or invalid(incomplete) XML. If i'm right, then you might have a timeout that expires sooner than the one you get in a real browser. Either that, or a connection that requires either connection-close or keepalive(i've seen servers broken like this).

Also, make sure you dont have a firewall on the server where the client runs that might block the xmlReader from talking to the xmlWriter:) Try iptables -L in the server console to check any firewall rules.


Edit: you might also need to call something like xmlReader->close(), or end() or whatever member you got there that closes the connection and signals the client that the transmission is over.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜