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 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,如何解決?