1

I am using a variation of the familiar readfile_chunked in attempt of download for larger files:

    function readfile_chunked($filename)
    {
            $chunk_size = 1*(1024*1024); // how many bytes per chunk
            $buffer = '';
            $handle = fopen($filename, 'rb');
            if ($handle === false)
            {
                    return false;
            }

            while (!feof($handle))
            {
                    $buffer = fread($handle, $chunk_size);
                    print $buffer;
                    ob_flush();
                    flush();
                    sleep(1);
            }
            $status = fclose($handle);
            return $status;
    }

smaller files work fine, but this larger file is missing the last 2830 bytes.

Shane
  • 11
  • 2

1 Answers1

0

i found out the issue to this. under the php.ini file, make sure you set implicit_flushing to On. i still have the explicit flush code after each line outputted however.

Shane
  • 11
  • 2
  • i also made sure all zlib settings were commented out. I had originally set them when I thought I needed them for the ZipArchive utility – Shane Jul 30 '10 at 04:32
  • Just as a note for future people looking at this, setting `implicit_flush` to `On` can have pretty severe performance implications. Use it as a debugging tool, but don't leave it on for production. Call `flush()` after the things you need to actually flush, instead. – tacotuesday Feb 07 '14 at 19:08