0

I have a string of about 6350268 characters and when I output them to the browser it takes up at least 700ms, but usually 900ms to 1000ms of extra execution time to output it.

The generation only takes up about 300ms, but together it's almost a whole second.

Is there a way to speed up echo output? or is it limited by the browser to which it is outputted?

    // What this code does is take about 20.000 urls in the database and
    // and transform it into a collapsable folder tree
    // this process generates about 6300000 characters in about 300ms.

    $this->benchmark->mark('code_start');
    $query = $this->db->query("SELECT `url` from `site_pages` WHERE `url` not like '' order by `url` ASC");
    $arr = array();
    foreach($query->result() as $result)
        {
        $arr[$result->url] = $result->url;
        }
    $tree = $this->explodeTree($arr,'/',true);
    $str = $this->plotTree($tree);
    echo $str;
    $this->benchmark->mark('code_end');
    echo $this->benchmark->elapsed_time('code_start', 'code_end');
    echo "<P>done";
Tschallacka
  • 27,901
  • 14
  • 88
  • 133
  • What happens to performance when you comment out the echo? How about when you turn on output buffering? You're talking about six megs of data here, there *is* going to be some processing time involved... – Charles Dec 18 '12 at 10:11
  • 1
    You're outputting **6MB** to the browser? Whichever way you look at it, everything about that process is bound to be slow... – deceze Dec 18 '12 at 10:12
  • 1
    if I comment out the echo it only takes 300-360ms to generate the content. I must note that my server uses gzip compression so actual output is a lot smaller. – Tschallacka Dec 18 '12 at 10:12
  • 1
    My guess would be a combination of PHP buffers and the web server buffering/sending the content is what's taking so much time. Worrying about this particular bottleneck seems like the wrong point to focus on. You should not dump 6MB of data on the browser but use gentler AJAX loading. – deceze Dec 18 '12 at 10:14
  • 1
    Kill the gzip compression and try again. – Charles Dec 18 '12 at 10:14
  • with gzip it's 600kb, takes way less time to load. without gzip I'm at about 3-5seconds of loading time, so killing gzip is no option. The php buffer is instantly full, but it gets output in 2 parts, after about 700 ms it outputs the first 3/4th and then when it's finished the last 1/4th. – Tschallacka Dec 18 '12 at 11:08
  • What happens when you use output buffering, with [`ob_start`](http://php.net/ob_start) asked to use a chunk size of zero? – Charles Dec 18 '12 at 20:52
  • @deceze could you please post your answer in an answer? I decided to go with ajax and it works a lot smoother now thanks to your suggestion. – Tschallacka Dec 19 '12 at 08:12

1 Answers1

0

You're outputting 6MB to the browser? Whichever way you look at it, everything about that process is bound to be slow. My guess would be a combination of PHP buffers and the web server buffering/sending the content is what's taking so much time. Worrying about this particular bottleneck seems like the wrong point to focus on. You should not dump 6MB of data on the browser but use gentler AJAX loading.

deceze
  • 510,633
  • 85
  • 743
  • 889