dsq2015 2016-07-05 11:26
浏览 61
已采纳

如果正在进行流式下载,Nginx PHP-FPM无法提供请求

In have setup two apps deployed on Nginx, one is in PHP and other is in Python.

Python based app is REST API application deployed on Nginx using uwsgi. One API serves CSV download. CSV files mostly large size above 100 MB. So that API provides streaming download.

PHP application hosted on same Nginx using php-fpm consumes REST API. In case of CSV download PHP application makes requests to API and provides streaming download to further streaming download to user/browser. This things works fine.

Now problem is when download request in progress from PHP app and tried to make access other pages of php app then it does not loads(response) pages. if I cancel download request then it loads/response page(s) instantly.

In API if download streaming in progress other API requests response working so no issue with python application.

But for PHP app its not working. Tried different options like changing worker_processes, worker_connections in Nginx. Also pool manager configuration in php-fpm. No success.

To make request to REST API from PHP application I have used PHP curl i.e curl.

Please help.

  • 写回答

1条回答 默认 最新

  • duanbi8089 2016-08-08 14:23
    关注

    Finally problem solved, It was mainly session lock issue.

    You need to have callback function to handle session close and also to write received data,

    Callback function:

    function curlWriteHandler($ch, $data)
        {
            echo $data;
            session_write_close();
            return strlen($data);
    }
    

    & set callback as,

    curl_setopt($ch, CURLOPT_WRITEFUNCTION, 'curlWriteHandler');
    

    Got reference from following answers/link (I don't know its good idea to specify link in answer, still)

    What for do we use CURLOPT_WRITEFUNCTION in PHP's cURL?

    How use CURLOPT_WRITEFUNCTION when download a file by CURL

    & https://curl.haxx.se/libcurl/c/CURLOPT_WRITEFUNCTION.html

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

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料