服务器 A 使用 xmlreader 从服务器 B 上的 xmlwriter 读取 XML
我有两台服务器
服务器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 会输出该文件。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试添加
否则读者会将其视为简单文本并且不起作用。尝试在文件的开头给出该内容。
did u tried adding
Else the reader will consider it as simple text and wont work. Try giving that at the begining of the file.
默认情况下,作者将缓冲您的输出。
一旦完成,你必须调用flush()。
顺便一提:
在哪里关闭记录元素?
By default the writter will buffer your output.
Once you are done you MUST call flush().
By the way:
where do you close the records element?
尝试写入 xmlReader 在磁盘上读取的任何内容并检查生成的文件。我有预感它要么是空的,要么是无效(不完整)的 XML。
如果我是对的,那么您可能会遇到比在真实浏览器中遇到的超时更快的超时。要么是这样,要么是需要连接关闭或保持活动的连接(我见过服务器像这样损坏)。
另外,请确保运行客户端的服务器上没有防火墙,这可能会阻止 xmlReader 与 xmlWriter 通信:) 在服务器控制台中尝试 iptables -L 来检查任何防火墙规则。
编辑:您可能还需要调用诸如
xmlReader->close()
或end()
或您在那里获得的任何关闭连接并向客户端发出信号的成员表示传输已结束。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()
, orend()
or whatever member you got there that closes the connection and signals the client that the transmission is over.