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 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程