Google chrome doesn't behave the same as other browsers when encountering this nugget:
遇到此块时,Google Chrome的行为与其他浏览器的行为不同:
<?php
while (true) {
echo "<script type='text/javascript'>\n";
echo "alert('hello');\n";
echo "</script>";
flush();
sleep(5);
}
?>
It seems that it's waiting for the connection to terminate before doing anything.
在做任何事情之前,它似乎正在等待连接终止。
Other than polling how can I do a similar thing in Google Chrome?
除了投票,我如何在谷歌浏览器中做类似的事情?
6 个解决方案
#1
3
Some browsers require a certain number of bytes to be downloaded before rendering available data. I remember the last time I tried to do what you're doing I ended up having to dump something like 300 spaces to be sure the browser would bother with it.
某些浏览器在呈现可用数据之前需要下载一定数量的字节。我记得上一次我试图做你正在做的事情我最终不得不转储300个空格,以确保浏览器会烦恼。
#2
4
I had a similar issue to this, and solved it by adding an HTML tag (in my case <br />) before each flush.
我有一个类似的问题,并通过在每次刷新之前添加一个HTML标签(在我的情况下
)来解决它。
My guess would be that Chrome waits for an element which is being displayed to close before triggering a re-render. That's only a guess though.
我的猜测是Chrome会在触发重新渲染之前等待显示关闭的元素。这只是猜测。
It didn't seem to require 1024 bytes - I think I would have had just under 512 bytes when it worked.
它似乎不需要1024字节 - 我认为当它工作时我会有不到512字节。
#3
1
I wish I had access to Chrome at the moment to test out some ideas. Have you tried adding some HTML after </script>
and seeing if it renders incrementally? I imagine it would, and if so that'd be proof that Chrome doesn't want to run javascript in <script>
elements while the page is loading. Of course, rendering the markup might trigger your scripts to run. If not, you could try including the javascript as external files and see if that affects execution time.
我希望我现在可以访问Chrome以测试一些想法。您是否尝试在 之后添加一些HTML并查看它是否以递增方式呈现?我想它会,如果是这样,那就证明Chrome不想在页面加载时在
I think browsers generally have some leeway according to the spec in when they begin executing javascript, especially as the page loads. It might not be possible to do this in a fully cross-browser way without polling.
我认为浏览器在开始执行javascript时根据规范通常会有一些余地,特别是在页面加载时。在没有轮询的情况下,可能无法以完全跨浏览的方式执行此操作。
#4
0
Did you talk with Chrome developers? Did you open a bug about that? IMHO the best solution is make Chrome behave like other browsers do, rather than having a workaround for it.
您是否与Chrome开发人员交谈过?你有没有打开一个bug?恕我直言,最好的解决方案是让Chrome的行为像其他浏览器一样,而不是为它做一个解决方法。
Okay, actually you probably will need a short-term workaround. But imagine a world in which each browser behaves differently in each aspect, say HTTP, HTML, CSS handling... it would not be a pleasant place!
好的,实际上你可能需要一个短期的解决方法。但想象一下这样一个世界:每个浏览器在每个方面都表现不同,比如HTTP,HTML,CSS处理......这不是一个令人愉快的地方!
#5
0
Stream is working. The answer from eyelidlessness is the solution.
流正在运行。眼睑的答案就是解决方案。
print "2048 points[BR>\n";
打印“2048分[BR> \ n”;
The [ = <
[= <
BTW look at the user-agent. Safari needs much bytes too. I think 1024. Firefox needs not so much bytes.
BTW看看用户代理。 Safari也需要很多字节。我认为1024. Firefox不需要那么多字节。
#6
0
<?php
$i = 0;
while (true) {
if($i == 0) {
echo "<html><body>";
}
echo "<script type='text/javascript'>\n";
echo "alert('hello');\n";
echo "</script>";
if($i == 0 ) {
$padstr = str_pad("",2048," ");
echo $padstr;
echo "</body></html>";
}
flush();
sleep(5);
$i = $i + 1;
}
?>
For fist time send at least 2048 bytes of data. then it will work fine. And make sure to keep script tag in a body tag. The strange thing is , in my case if I add 1024 bytes it worked. Hope this helps you
首次发送至少2048字节的数据。然后它会正常工作。并确保将script标记保存在body标记中。奇怪的是,在我的情况下,如果我添加1024字节,它工作。希望这对你有所帮助
The above program is working fine in google chrome.
以上程序在谷歌浏览器中运行良好。
#1
3
Some browsers require a certain number of bytes to be downloaded before rendering available data. I remember the last time I tried to do what you're doing I ended up having to dump something like 300 spaces to be sure the browser would bother with it.
某些浏览器在呈现可用数据之前需要下载一定数量的字节。我记得上一次我试图做你正在做的事情我最终不得不转储300个空格,以确保浏览器会烦恼。
#2
4
I had a similar issue to this, and solved it by adding an HTML tag (in my case <br />) before each flush.
我有一个类似的问题,并通过在每次刷新之前添加一个HTML标签(在我的情况下
)来解决它。
My guess would be that Chrome waits for an element which is being displayed to close before triggering a re-render. That's only a guess though.
我的猜测是Chrome会在触发重新渲染之前等待显示关闭的元素。这只是猜测。
It didn't seem to require 1024 bytes - I think I would have had just under 512 bytes when it worked.
它似乎不需要1024字节 - 我认为当它工作时我会有不到512字节。
#3
1
I wish I had access to Chrome at the moment to test out some ideas. Have you tried adding some HTML after </script>
and seeing if it renders incrementally? I imagine it would, and if so that'd be proof that Chrome doesn't want to run javascript in <script>
elements while the page is loading. Of course, rendering the markup might trigger your scripts to run. If not, you could try including the javascript as external files and see if that affects execution time.
我希望我现在可以访问Chrome以测试一些想法。您是否尝试在 之后添加一些HTML并查看它是否以递增方式呈现?我想它会,如果是这样,那就证明Chrome不想在页面加载时在
I think browsers generally have some leeway according to the spec in when they begin executing javascript, especially as the page loads. It might not be possible to do this in a fully cross-browser way without polling.
我认为浏览器在开始执行javascript时根据规范通常会有一些余地,特别是在页面加载时。在没有轮询的情况下,可能无法以完全跨浏览的方式执行此操作。
#4
0
Did you talk with Chrome developers? Did you open a bug about that? IMHO the best solution is make Chrome behave like other browsers do, rather than having a workaround for it.
您是否与Chrome开发人员交谈过?你有没有打开一个bug?恕我直言,最好的解决方案是让Chrome的行为像其他浏览器一样,而不是为它做一个解决方法。
Okay, actually you probably will need a short-term workaround. But imagine a world in which each browser behaves differently in each aspect, say HTTP, HTML, CSS handling... it would not be a pleasant place!
好的,实际上你可能需要一个短期的解决方法。但想象一下这样一个世界:每个浏览器在每个方面都表现不同,比如HTTP,HTML,CSS处理......这不是一个令人愉快的地方!
#5
0
Stream is working. The answer from eyelidlessness is the solution.
流正在运行。眼睑的答案就是解决方案。
print "2048 points[BR>\n";
打印“2048分[BR> \ n”;
The [ = <
[= <
BTW look at the user-agent. Safari needs much bytes too. I think 1024. Firefox needs not so much bytes.
BTW看看用户代理。 Safari也需要很多字节。我认为1024. Firefox不需要那么多字节。
#6
0
<?php
$i = 0;
while (true) {
if($i == 0) {
echo "<html><body>";
}
echo "<script type='text/javascript'>\n";
echo "alert('hello');\n";
echo "</script>";
if($i == 0 ) {
$padstr = str_pad("",2048," ");
echo $padstr;
echo "</body></html>";
}
flush();
sleep(5);
$i = $i + 1;
}
?>
For fist time send at least 2048 bytes of data. then it will work fine. And make sure to keep script tag in a body tag. The strange thing is , in my case if I add 1024 bytes it worked. Hope this helps you
首次发送至少2048字节的数据。然后它会正常工作。并确保将script标记保存在body标记中。奇怪的是,在我的情况下,如果我添加1024字节,它工作。希望这对你有所帮助
The above program is working fine in google chrome.
以上程序在谷歌浏览器中运行良好。