相关疑难解决方法(0)

如何让PHP生成Chunked响应

我搜索了这个问题,但没有答案.

我希望我的PHP脚本在chunked中生成HTTP响应(http://en.wikipedia.org/wiki/Chunked_transfer_encoding).怎么做?

更新:我明白了.我必须指定Transfer-encoding标头并刷新它.

header("Transfer-encoding: chunked");
flush(); 
Run Code Online (Sandbox Code Playgroud)

冲洗是必要的.否则,将生成Content-Length标头.

而且,我必须自己制作块.有了辅助功能,并不难.

function dump_chunk($chunk)
{
    echo sprintf("%x\r\n", strlen($chunk));
    echo $chunk;
    echo "\r\n";
}
Run Code Online (Sandbox Code Playgroud)

php http chunked-encoding

31
推荐指数
4
解决办法
3万
查看次数

内容长度标头始终为零

我通过以下方式设置标题:

header('Content-Length: ' . filesize($strPath));
Run Code Online (Sandbox Code Playgroud)

在我的带有 ZendServer 的 PC 上它工作正常,我可以下载文件大小正确的文件。在生产服务器上,一个带有 Apache 和编译 PHP 的 Solaris,我得到一个文件大小为零的文件,所以是一个空文件。

有配置参数吗?可以阻止设置“内容长度:1222”的东西?

谢谢。

编码:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');

require 'includes/prepend.inc.php';
require __ADMIN_DIR__.'/AdminInfo.php';
$intFile = QApplication::QueryString('fileID');
if($intFile == '') die('Error: missing ID');
$objFile = File::Load($intFile);
$blnRight = false;
$objAdminInfo = new AdminInfo();
if($objAdminInfo->isAdmin()) {
    $blnRight = true;
}
else {
    $objSecMan = new SecurityManager(
        'file:'.$objFile->FileID, 
        $objAdminInfo->getUserID()
    );
    $blnRight = $objSecMan->processResource('view');
}

// if the user can modify and or publish, can even view the file
if(!$blnRight) { …
Run Code Online (Sandbox Code Playgroud)

php apache header content-length

2
推荐指数
1
解决办法
1万
查看次数

标签 统计

php ×2

apache ×1

chunked-encoding ×1

content-length ×1

header ×1

http ×1