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.

图片转代码服务由CSDN问答提供 功能建议

在Nginx上安装了两个应用程序,一个在PHP中,另一个在Python中。 \ n

基于Python的应用程序是使用uwsgi部署在Nginx上的REST API应用程序。 一个API提供CSV下载。 CSV文件大多数大于100 MB。 因此,API提供流式下载。

使用php-fpm在同一个Nginx上托管的PHP应用程序使用REST API。 在CSV下载的情况下,PHP应用程序向API发出请求并提供流式下载以进一步流式下载到用户/浏览器。 这个工作正常。

现在问题是当PHP应用程序正在进行下载请求并尝试访问php应用程序的其他页面时,它不会加载(响应)页面。 如果我取消下载请求,那么它会立即加载/响应页面。

在API中,如果正在进行下载流,其他API请求响应正常,因此python应用程序没有问题。

但对于PHP应用程序,它不起作用。 提供了不同的选项,例如在Nginx中更改worker_processes,worker_connections。 还有php-fpm中的池管理器配置。 没有成功。

要从PHP应用程序向REST API发出请求,我使用了PHP curl,即curl。

请帮忙。 \ n

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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

    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题