Why I get “ERR_RESPONSE_HEADERS_TOO_BIG” on chrome?

The following code is executed correctly on firefox, but not on Chrome. The later always displays “ERR_RESPONSE_HEADERS_TOO_BIG”. This error occurs when I iterate through a folder containing more than 10000 items (files) – it must be long task.

Please can anyone explain me how to avoid this error? The error disappears if I “echo”-ing something just after ob_end_clean();

<?php

ini_set('max_execution_time', 600);

function FileItemsCount($it, &$count_ref)
{ 
   foreach ($it as $file)
   {
        $count_ref += 1;

ob_start();
        session_start();
        $_SESSION['progress'] = $count_ref;
        session_write_close(); 
ob_end_clean() ;

        $is_folder = $it->hasChildren();
        if ($is_folder)
        {
           FileItemsCount($it->getChildren(), $count_ref);
        }
    }
}

$dir = "C:/Users/sstefanov/xampp";

$it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS);

$count = 0;
FileItemsCount($it, $count);


echo $count;

?>

Leave a Comment