dongpangzan6425 2019-04-12 07:55 采纳率: 100%
浏览 128

如何使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?

  • 写回答

2条回答 默认 最新

  • dongshuao2309 2019-04-12 08:08
    关注

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

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

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献