Google Chrome and HTTP streaming connections?

Google Chrome does not behave like other browsers when faced with this screw:

<?php
while (true) {
    echo "<script type='text/javascript'>\n";
    echo "alert('hello');\n";
    echo "</script>";
    flush();

    sleep(5);
}
?>

It seems to be waiting for the connection to complete before doing anything.

Besides polling, how can I do this in Google Chrome?

+3
source share
6 answers

Some browsers require a certain number of bytes to load before providing available data. I remember the last time I tried to do what you were doing, I had to drop something like 300 spaces to make sure the browser worked with it.

+3
source

, , HTML- ( < br/" > ) .

, Chrome , , , , . .

, 1024 - , 512 , .

+4

Chrome , . HTML </script> , ? , , , Chrome javascript <script> . , . , javascript , .

, , javascript, . , .

+1

Chrome? ? IMHO - Chrome , , , .

, , , . , - , , HTTP, HTML, CSS... !

0

. - .

print "2048 [BR > \n";

[= <

-. . , 1024. Firefox .

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,"&nbsp;");
        echo $padstr;
        echo "</body></html>";
    }
    flush();

    sleep(5);
    $i = $i + 1;
}
?>

For the first time, send at least 2048 bytes of data. then it will work fine. And don't forget to save the script tag in the body tag. The strange thing is, in my case, if I add 1024 bytes, it worked. Hope this helps you.

The above program works fine in google chrome.

0
source

Source: https://habr.com/ru/post/1698719/


All Articles