使用PHP下载大型文件时服务器失败 [英] Server fails when downloading large files with PHP

查看:174
本文介绍了使用PHP下载大型文件时服务器失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PHPSecLib 的SFTP功能从FTP服务器下载文件。

I'm using the SFTP functions of PHPSecLib to download files from an FTP server.

$sftp->get($fname);

如果文件最多可达200​​MB,但如果是300MB,浏览器会以Firefox can在[download.php]找不到该文件。也就是说,它说它找不到用于下载远程文件的php文件。

works if the file is up to 200MB, but if it's 300MB, the browser responds with "Firefox can't find the file at [download.php]". That is, it says it can't find the php file I use for downloading the remote file.

起初我以为这是由于$ code > memory_limit 设置在php.ini中,但如果设置为128M或350M,则无关紧要; 200MB文件仍然可以工作,300MB文件失败。而且在十秒钟后失败,所以 max_execution_time max_input_time 似乎不是罪魁祸首。什么可能是错的?

At first I thought this was due to the memory_limit setting in php.ini, but it doesn't matter if it's set to 128M or 350M; 200MB files still work, and 300MB files fail. And it fails after ten seconds, so max_execution_time or max_input_time don't seem to be the culprits. What could be wrong?

推荐答案

还有什么可以做的...

Something else you could do...

<?php
include('Net/SFTP.php');

$sftp = new Net_SFTP('www.domain.tld');
$sftp->login('username', 'password');

$start = 0;
while (true) {
    $response = $sftp->get('1mb', false, $start, 1024);
    $start+= 1024;
    if (empty($response)) {
        break;
    }
    echo $response;
}

ie。下载多个块的文件。

ie. download the file in multiple chunks.

这篇关于使用PHP下载大型文件时服务器失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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