4

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 xmlreader 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.

ajreal
  • 46,720
  • 11
  • 89
  • 119
user326096
  • 307
  • 1
  • 4
  • 11

3 Answers3

1

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.

Anush Prem
  • 1,511
  • 8
  • 16
0

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?

Oliver A.
  • 2,870
  • 2
  • 19
  • 21
0

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.

Quamis
  • 10,924
  • 12
  • 50
  • 66