V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
wbing
V2EX  ›  问与答

用 libcurl 库将多个文件上传 ftp 服务器上, curl_easy_perform 太耗时了,怎么解决?

  •  
  •   wbing · 2017-03-16 10:57:11 +08:00 · 2780 次点击
    这是一个创建于 2655 天前的主题,其中的信息可能已经有所发展或是发生改变。

    这是设置的参数

    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_USERPWD, user_key);
    curl_easy_setopt(curl, CURLOPT_READDATA, file);
    curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L);
    curl_easy_setopt(curl, CURLOPT_INFILESIZE, get_file_size(file));
    curl_easy_setopt(curl, CURLOPT_FTP_CREATE_MISSING_DIRS, 1);
    curl_easy_setopt(curl, CURLOPT_READFUNCTION, read_callback);
    

    文件不大,只有 10K 左右,网络正常,但每次curl_easy_perform 耗时都是2000+毫秒

    4 条回复    2017-03-17 08:28:17 +08:00
    BOYPT
        1
    BOYPT  
       2017-03-16 11:09:12 +08:00   ❤️ 1
    curl_setopt($curlhandle, CURLOPT_VERBOSE, true);

    设置 verbose 看看具体 log ,耗时在什么地方
    wbing
        2
    wbing  
    OP
       2017-03-16 19:27:06 +08:00
    @BOYPT

    ```
    < 229 Entering Extended Passive Mode (|||65444|)
    *Trying 127.0.0.1...
    * Connecting to 10.0.0.182 <10.0.0.182> port 65444
    ```

    卡在这了,搜了下网上也有出现 Entering Extended Passive Mode 的问题
    BOYPT
        3
    BOYPT  
       2017-03-16 23:17:18 +08:00   ❤️ 1
    @wbing 应该查到原因吧?
    估计是 NAT 导致的 EPSV 兼容问题,配置 CURLOPT_FTP_USE_EPSV False 应该可以解决
    wbing
        4
    wbing  
    OP
       2017-03-17 08:28:17 +08:00 via iPhone
    @BOYPT 对,就是这个原因。昨晚设置这个参数为 false 后就正常了
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2326 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 02:22 · PVG 10:22 · LAX 19:22 · JFK 22:22
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.