如何使webapp(PHP)在漫长的等待时间后从API(Python)接收响应?

I have a web application written in PHP, running on a Linux Azure virtual machine with NGINX. The application is connected to an API (written in Python) on a separate server with NGINX (similar Linux Azure virtual machine). This API performs a complex operation which takes between 30sec and 20 min to complete. So the application has to wait for it.

The problem is that with long wait times, the API respond is not registered in the web app. I have tried the following:

— verified in the endpoint of the API and the logs that the API provides a response after long processing times (it does)

I suspect it is a timeout issue so have tried:

— fixed the PHP timeout settings and the timeout for the  /login_c/check_login endpoint

— checked the code for the request and response sent and received from the API, where I am using curl method. This is the parameter for the time out of curl:

curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 2100);".

The exec method executes in the background:

exec($command);

The following articles did not provide a solution:

Setting Curl's Timeout in PHP

PHP cURL methods time out on some URLs, but command line always works

Any advice on how to solve this problem?

You must edit php.ini or add to php script:

ini_set("max_execution_time",1800); //for 30 minutes request

It seems that this solved the problem:

curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 2100);".