大字体/echo 中断 http 响应

发布于 2024-12-06 06:29:12 字数 898 浏览 0 评论 0原文

我遇到返回大量数据的回显/打印问题。响应已损坏,如下所示:

  • end of data
  • http 响应标头打印在 body
  • start of data

我正在浏览器中运行以下脚本来复制问题:

<?php

// Make a large array of strings
for($i=0;$i<10000;$i++)
{        
  $arr[] = "testing this string becuase it is must longer than all the rest to see if we can replicate the problem. testing this string becuase it is must longer than all the rest to see if we can replicate the problem. testing this string becuase it is must longer than all the rest to see if we can replicate the problem.";
}

// Create one large string from array
$var = implode("-",$arr);

// Set HTTP headers to ensure we are not 'chunking' response
header('Content-Length: '.strlen($var)); 
header('Content-type: text/html');

// Print response
echo $var;

?>

这里发生了什么?

其他人可以尝试这个吗?

I am having a problem with an echo/print that returns a large amount of data. The response is broken and is as follows:

  • end of data
  • http response header printed in body
  • start of data

I am running the following script to my browser to replicate the problem:

<?php

// Make a large array of strings
for($i=0;$i<10000;$i++)
{        
  $arr[] = "testing this string becuase it is must longer than all the rest to see if we can replicate the problem. testing this string becuase it is must longer than all the rest to see if we can replicate the problem. testing this string becuase it is must longer than all the rest to see if we can replicate the problem.";
}

// Create one large string from array
$var = implode("-",$arr);

// Set HTTP headers to ensure we are not 'chunking' response
header('Content-Length: '.strlen($var)); 
header('Content-type: text/html');

// Print response
echo $var;

?>

What is happening here?

Can someone else try this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

向地狱狂奔 2024-12-13 06:29:12

您的服务器上可能激活了自动输出缓冲。如果缓冲区溢出,它只会开始倒出其余数据。

请注意,gzip 压缩之类的东西也会隐式缓冲输出。如果是这种情况,在标头之后调用 ob_end_flush() 应该可以解决该问题。

You might have automatic output buffering activated on your server. If the buffer overflows, it just starts pooping out the rest of the data instead.

Note that something like gzip compression also implicitly buffers the output. If it's the case, an ob_end_flush() call after the headers should solve it.

-柠檬树下少年和吉他 2024-12-13 06:29:12

浏览器通常会限制允许通过 get 变量传递的字符。
要解决此问题,您可以对字符串进行 Base 64 编码,然后在收到响应后对其进行解码。

我认为有 javascript base 64 编码库可用。
就像这个:
http://www.webtoolkit.info/javascript-base64.html

Browsers often limits the characters you're allowed to pass through a get variable.
To work around this, you could base 64 encode the string, and then decode it, once you recievede the respone.

I think there's javascript base 64 encode libraries available.
Like this one:
http://www.webtoolkit.info/javascript-base64.html

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