anils
anils

Reputation: 1962

Nginx PHP-FPM not serve request if streaming download in progress

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.

Upvotes: 3

Views: 522

Answers (1)

anils
anils

Reputation: 1962

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

Upvotes: 1

Related Questions