如何通过 HTTP 协议找出数据缓冲的位置?
我正在尝试使用 php5/apache2 的早期刷新来执行一些代码,渲染一些 json,然后执行代码的另一部分,该部分需要几秒钟但不会产生任何响应。 到目前为止的基本代码是:
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
echo 'Page loading'; // code to render;
ob_flush();
flush();
sleep(29); // LONG time code to execute
前面的示例不起作用。我的意思是它会在 29 秒后回显“页面加载”。 如果我查看 http 响应,我会发现:
(Status-Line) HTTP/1.1 200 OK
Date Mon, 04 Jul 2011 19:49:19 GMT
Server Apache/2.2.11 (Win32) mod_ssl/2.2.11 OpenSSL/0.9.8k PHP/5.3.0
X-Powered-By PHP/5.3.0
Expires Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma no-cache
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Transfer-Encoding chunked
Content-Type text/html
我的问题并不是它为什么不起作用?但是我如何检查字符串的缓冲位置? 我知道有不同的缓冲区: - php 输出缓冲区、php zlib.buffer - apache mode_deflate / gzip - 浏览器缓冲
所有 php 输出缓冲均已关闭,apache mode_deflate 已激活,但如您所见,传输编码已“分块”。 我不知道如何找出问题所在,我正在使用 HttpFox 查看标头,并尝试获取 HTTP 请求的内容,HttpFox 说内容在 29 秒完成之前尚未准备好。
有什么建议吗?
I'm trying to use early flush with php5/apache2 to execute some code, render some json and after that executing another part of the code that take several second but doesn't produce any response.
The basic code so far is:
@apache_setenv('no-gzip', 1);
@ini_set('zlib.output_compression', 0);
echo 'Page loading'; // code to render;
ob_flush();
flush();
sleep(29); // LONG time code to execute
The previous example does not work. I mean it will echo 'Page loading' after 29seconds.
If I looked at the http response I have:
(Status-Line) HTTP/1.1 200 OK
Date Mon, 04 Jul 2011 19:49:19 GMT
Server Apache/2.2.11 (Win32) mod_ssl/2.2.11 OpenSSL/0.9.8k PHP/5.3.0
X-Powered-By PHP/5.3.0
Expires Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma no-cache
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Transfer-Encoding chunked
Content-Type text/html
My problem is not really why it doesnt work? but How can I checked where my string get buffered?
I know that there is different buffer:
- php output_buffer, php zlib.buffer
- apache mode_deflate / gzip
- browser buffering
All php output buffering are off, apache mode_deflate is activated but as you can see the transfer-encoding is "chunked".
I have no idea how to find out where is my problem, I'm using HttpFox to see the header and I try to get the content of the HTTP request, HttpFox say that the content is not ready until the 29seconds are done.
Any advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,您尝试过 ob_get_level() 吗?
Hmm have you tried ob_get_level() ?
马克 B 是对的......
我必须做一个 1000 的循环,并激活 output_buffering
才能在睡眠前看到结果。
我必须循环 100,并且 output_buffering = off 才能得到相同的结果。
Marc B was right...
I had to make a loop of a 1000, with output_buffering activated
To be able to see result before the sleep.
I have to to a loop of 100, with output_buffering = off to get the same result.