Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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'>\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?

like image 557
Allain Lalonde Avatar asked Oct 30 '25 02:10

Allain Lalonde


1 Answers

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.

like image 162
thomasrutter Avatar answered Nov 01 '25 17:11

thomasrutter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!