duanchi3109 2014-02-06 11:46
浏览 118
已采纳

PHP:从ftp服务器获取文件(proftpd)

I have website, wich loads config files (5-15 per 1 webpage) from remote ftp servers (linux proftpd).

When user opens (refresh) only one web-page - everything is fine, page renders to fast (~100 milliseconds). When user open 4-6 tabs one by one (~1 sec delay between opening tabs) on web browser, avg 1-3 web-pages renders to fast, but 4-6 pages it too sloooow (up to 60 seconds or more).

I find bottleneck: this is ftp_get() php function, that freeze to time of timeout set in ftp_connect() when getting files from ftp. Only ftp_get() freeze web-page rendering.

public function getConfigViaFtp($config_name)
{
    $handle = fopen('php://temp', 'r+');
    ftp_fget($this->getFtpConnectionStream(), $handle, $config_name, FTP_ASCII);
    rewind($handle);

    return stream_get_contents($handle);
}

I am ssh to remote ftp server and run ftptop to look on the connections when page freeze. proftpd have only one connection with COMMAND 'RETR'.

ftp_get always succesfuly get first (sometimes up to 5 files) file from ftp, but another files always empty (but exists and not empty on the ftp server) and ftp_get timeouts on this files.

I try to:

ob_start(); 
$result = ftp_get($this->getFtpConnectionStream(), 'php://output', $config_name, FTP_ASCII);
$data = ob_get_contents();
ob_end_clean();

try ftp_pasv()

but nothing :( ftp_get() and web-page still freeze a lot of time and doesn't load contents of files in end of each web-page.

Whats wrong? proftpd settings (default) or something else?

  • 写回答

1条回答 默认 最新

  • douyan7916 2014-02-07 12:03
    关注

    SOLVED: ftp_pasv() right after ftp_login(), but NOT after ftp_connect and everithing works fine :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?