Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;

?>
like image 752
netanalyzer Avatar asked Jun 19 '13 08:06

netanalyzer


2 Answers

It's not the case in this questions, but I thought that it would be useful to share that this error could also arise if too much data is being printed/echoed by the server (e.g. for debugging purposes)

like image 192
elachell Avatar answered Oct 17 '22 10:10

elachell


Some necroposting for those, who will search an answer :)

I tried to do the similar thing - to unblock parallel ajax requests, one of which called for long operation and other for checking progress. I also started the session each time to write new value and stopped it right after. And I also got ERR_RESPONSE_HEADERS_TOO_BIG error in Chrome.

The reason was that PHP sent Set-Cookie header with each session start in my case. And when long ajax request was finishing, server sent all Set-Cookie headers to the browser.

To fix this I removed the Set-Cookie headers by calling header_remove('Set-Cookie'); before the output.

like image 35
gorodezkiy Avatar answered Oct 17 '22 12:10

gorodezkiy