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";
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.