服务器 A 使用 xmlreader 从服务器 B 上的 xmlwriter 读取 XML

发布于 2024-10-05 21:09:04 字数 848 浏览 5 评论 0原文

我有两台服务器

服务器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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

森林很绿却致人迷途 2024-10-12 21:09:04

您是否尝试添加

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

否则读者会将其视为简单文本并且不起作用。尝试在文件的开头给出该内容。

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.

野鹿林 2024-10-12 21:09:04

默认情况下,作者将缓冲您的输出。
一旦完成,你必须调用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 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?

潜移默化 2024-10-12 21:09:04

尝试写入 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(), or end() or whatever member you got there that closes the connection and signals the client that the transmission is over.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文