Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

php - Google Chrome and Streaming HTTP connections?

Google chrome doesn't behave the same as other browsers when encountering this nugget:

<?php
while (true) {
    echo "<script type='text/javascript'>
";
    echo "alert('hello');
";
    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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had a similar issue to this, and solved it by adding an HTML tag (in my case <br />) before each flush.

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.

It didn't seem to require 1024 bytes - I think I would have had just under 512 bytes when it worked.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...