php回显大量数据

php回显大量数据,php,apache,flash,Php,Apache,Flash,我正在使用echo将各种文件输出到浏览器,包括一些10MB+的.swf文件。我正在经历的一个负面影响是,它似乎弄乱了内容中的一些flash预加载程序,例如,导致图像闪烁而不是显示稳定的进度条。我想知道是否有任何类型的缓冲正在进行或任何其他我可以做的事情来修复它 对于一些背景信息,我必须间接提供内容的原因是,它被设计为只提供给授权用户,因此脚本首先检查用户是否具有适当的权限,然后将readfile()与echo配对。也许有更好的方法,我愿意接受各种想法 编辑: readfile()和echo当然是

我正在使用
echo
将各种文件输出到浏览器,包括一些10MB+的.swf文件。我正在经历的一个负面影响是,它似乎弄乱了内容中的一些flash预加载程序,例如,导致图像闪烁而不是显示稳定的进度条。我想知道是否有任何类型的缓冲正在进行或任何其他我可以做的事情来修复它

对于一些背景信息,我必须间接提供内容的原因是,它被设计为只提供给授权用户,因此脚本首先检查用户是否具有适当的权限,然后将
readfile()
echo
配对。也许有更好的方法,我愿意接受各种想法

编辑

readfile()
echo
当然是一种简单的解释方法。它运行类似于:

<?php
check_valid_user();
ob_start();
// set appropriate headers for content-type etc
set_headers($file);

readfile($file);

$contents = ob_get_contents();
ob_end_clean();
if (some_conditions()) {
    // does some extra work on html files (adds analytics tracker)
}

echo $contents;
exit;
?>

您很可能会使用/etc与/echo&。如果尚未设置内容类型,则可能需要调用来预先设置内容类型。另外,如果使用输出缓冲,则需要调用

通过这种方式,您可以读取较小的数据片段并立即回显它们,而无需在输出之前缓冲整个文件。

您可以使用/etc和/echo&。如果尚未设置内容类型,则可能需要调用来预先设置内容类型。另外,如果使用输出缓冲,则需要调用


通过这种方式,您可以读取较小的数据片段并立即回显它们,而无需在输出之前缓冲整个文件。

您可能需要尝试设置内容长度标题

差不多

header('Content-Length: ' . filesize($file));

您可能需要尝试设置内容长度标题

差不多

header('Content-Length: ' . filesize($file));

我认为在这种情况下缓冲是多余的。你可以这样做:

<?php
    check_valid_user();
    // set appropriate headers for content-type etc
    set_headers($file);

    if (some_conditions())
    {
        $contents = file_get_contents($file);
        // does some extra work on html files (adds analytics tracker)
        // Send contents. HTML is often quite compressible, so it is worthwhile
        // to turn on compression (see also ob_start('ob_gzhandler'))
        ini_set('zlib.output_compression', 1);
        die($contents);
    }
    // Here we're working with SWF files.
    // It may be worthwhile to turn off compression (SWF are already compressed,
    // and so are PDFs, JPEGs and so on.
    ini_set('zlib.output_compression', 0);
    // Some client buffering schemes need Content-Length (never understood why)
    Header('Content-Length: ' . filesize($file));
    // Readfile short-circuits input and output, so doesn't use much memory.
    readfile($file);
    // otherwise:
    /*
    // Turn off buffering, not really needed here
    while(ob_get_level())
        ob_end_clean();
    // We do the chunking, so flush always
    ob_implicit_flush(1);

    $fp = fopen($file, 'r');
    while(!feof($fp))
        print fread($fp, 4096); // Experiment with this buffer's size...
    fclose($fp);
?>

我认为在这种情况下缓冲是多余的。你可以这样做:

<?php
    check_valid_user();
    // set appropriate headers for content-type etc
    set_headers($file);

    if (some_conditions())
    {
        $contents = file_get_contents($file);
        // does some extra work on html files (adds analytics tracker)
        // Send contents. HTML is often quite compressible, so it is worthwhile
        // to turn on compression (see also ob_start('ob_gzhandler'))
        ini_set('zlib.output_compression', 1);
        die($contents);
    }
    // Here we're working with SWF files.
    // It may be worthwhile to turn off compression (SWF are already compressed,
    // and so are PDFs, JPEGs and so on.
    ini_set('zlib.output_compression', 0);
    // Some client buffering schemes need Content-Length (never understood why)
    Header('Content-Length: ' . filesize($file));
    // Readfile short-circuits input and output, so doesn't use much memory.
    readfile($file);
    // otherwise:
    /*
    // Turn off buffering, not really needed here
    while(ob_get_level())
        ob_end_clean();
    // We do the chunking, so flush always
    ob_implicit_flush(1);

    $fp = fopen($file, 'r');
    while(!feof($fp))
        print fread($fp, 4096); // Experiment with this buffer's size...
    fclose($fp);
?>

readfile()
可能不与
echo()
配对,因为
readfile()
将其输出直接写入输出缓冲区。查看一些相关代码会更好。
readfile()
可能不与
echo()
配对,因为
readfile()
将其输出直接写入输出缓冲区。看到一些相关的代码会很好。我确实使用了这一行,以及六个其他相关的内容标题。您是否检查了标题是否设置为正确的值?我确实使用了这一行,以及六个其他相关的内容标题。您是否已检查以确保标题设置为正确的值?