[solved] Issues with streaming PHP/AJAX (using iframes)

    Date: 05/30/06 (PHP Community)    Keywords: php, html, xml, java

    This issue has been solved to a satisfactory level. Working example here.

    Hey folks. I've been attempting to replace some AJAX stuff that refreshed every X milliseconds using the XMLHTTP object, with a streaming equivalent using inline frames and PHP delays. However, i've hit a snag in that data seems to be sent out in 4kb chunks - far too large for my intended purpose.

    While this streaming example is fine providing that 4096 bytes of data is sent between each portion, this dosen't go very far towards increasing consecutive update speed and efficency (by preventing the constant cycle of connect-download-disconnect). I am aiming to only send out about 512 bytes from the server, per portion. I have yet to work out if the 4kb limit is being implemented by the client or the server.

    So basically what I want to do is be able to have the code below work without needing 4kb of useless padding.

    This code is not currently Moz/FF compatible, due to an issue with the way I move the content from the iframe with javascript (window.frames["streaming_iframe"].document.body.innerText returns "undefined" in FF).

    header("Cache-Control: no-cache, must-revalidate");

    echo "";

      if (@$_GET["stream"]) {
      
        for ($i=0;$i<10;$i++) {
            
          for ($x=0; $x<(1024 * 4); $x++) { //4kb chunks seem favoured?
          echo " "; // Padding
          }
          
        echo $i."\n\r";
        usleep(500000);
        }
      
    echo "
    ";

      exit;
      }
    ?>








    Solution:
    Inital padding with echo str_pad('',256)."\n"; (I feel that 256 bytes is an acceptable level of padding)
    Output flushinf with flush(); ob_flush();

    Code (for possible future reference):
    header("Cache-Control: no-cache, must-revalidate");

    echo "";

    if (@$_GET["stream"]) {
    echo str_pad('',256)."\n";

    for ($i=0;$i<10;$i++) {
    echo $i."\n\r";
    flush();
    ob_flush();
    usleep(500000);
    }

    echo "
    ";
    exit;
    }

    ?>





    Source: http://community.livejournal.com/php/454188.html

« altering title within body ? || stupid date formatting issue »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home