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 xmlreader on server A continues to complain that server B is not responding, although I can see the xml result in the browser.

To generate

takes less than a second.

If I copy xml to a static file, xmlreader will output the file.

+4
source share
3 answers

By default, the administrator will buffer your output. Once you're 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 item?

0
source

tried to add

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

Otherwise, the reader will consider it as simple text and will not work. Try to give this at the beginning of the file.

+1
source

Try to write everything that xmlReader reads on disk and check the generated file. I have a hunch its either empty or invalid (incomplete) XML. If I'm right, then you may have a timeout that expires earlier than the one you get in a real browser. Either this, or a connection that requires either a close-close connection or keepalive (I saw that the servers were broken like that).

Also, make sure that you do not have a firewall on the server that is running the client, which can block xmlReader from talking to xmlWriter. Try iptables -L in the server console to check any firewall rules.


Edit: You may also need to call something like xmlReader->close() or end() or any other member that you got there that closes the connection and signals to the client that the transfer is complete.

0
source

All Articles