“错误网关错误502”当试图下载服务器生成的.zip文件时 [英] "Bad Gateway Error 502" when trying to download server-generated .zip file

查看:404
本文介绍了“错误网关错误502”当试图下载服务器生成的.zip文件时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试下载服务器生成的.zip文件时遇到错误的网关错误502

I'm getting a "bad gateway error 502" when trying to download a server-generated .zip-file

我已经隔离了导致错误;它是:

I've isolated the line that causes the error; it's:

$zip->addFile($thumb->loadVersion($version['id']), $rank . "_" . $thumb->filename);

这是我的代码。我的脚本遍历用户上传的所有.jpg文件,将它们捆绑成一个大的.zip文件,并发送.zip文件的下载头文件。

Here's my code. My script loops through all the .jpg files users have uploaded, bundles them into one big .zip file, and sends download headers for the .zip file.

function downloadGalleryZip() {

    $tmpfile = tempnam("tmp", "zip");
    $zip = new ZipArchive();
    $res = $zip->open($tmpfile, ZipArchive::OVERWRITE);

    if ($res === TRUE) {

    // loop through gallery

    $sql = "SELECT * FROM files_versions WHERE file_id = ". $this->fileId . " AND deleted_on IS NULL ORDER BY rank ASC"; 
    $result = db_query($sql);
    $rank = 0;

        while ($version = mysql_fetch_array($result)) :
            $rank ++;
            $rank = str_pad($rank, 3, '0', STR_PAD_LEFT);
            $thumb = new fancyFile();
            $zip->addFile($thumb->loadVersion($version['id']), $rank . "_" . $thumb->filename);

        endwhile;  

        // $zip->addFromString('000_info.txt', 'Dieser Ordner wurde am ' . date("d.m.Y", time()) . ' heruntergeladen.');
        $zip->close();
    }


    $filename = getCaptionFromFile($this->fileId) . ".zip";

    header("Connection: Keep-Alive");
    header("Content-Description: File Transfer");
    header("Content-Disposition: attachment; filename=" . $filename);
    header("Content-Type: application/zip" );
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    header('Content-Length:' . filesize($tmpfile));
    ob_clean();
    flush();

}

我绝对没有经验糟糕的网关错误,非常感谢您的帮助!

I have absolutely no experience with "bad gateway errors", your help is very much appreciated!

谢谢,
马特

推荐答案

我已经解决了这个问题。

I've solved the problem.

原因是生成zip文件的时间超过5秒,而我的网关服务器的Timeout和KeepAliveTimeout设置为5秒。 (你可以在httpd.conf中编辑它)

The reason was generating the zip file took more than 5 seconds, and my gateway server had a Timeout and KeepAliveTimeout setting of 5 seconds. (you can edit that in httpd.conf)

我将Timeout增加到60秒 - 问题解决了。

I increased the Timeout to 60 seconds - problem solved.

这篇关于“错误网关错误502”当试图下载服务器生成的.zip文件时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆