首页 > 解决方案 > php api中的异步函数

问题描述

我希望你能帮帮我

我在 azure Web 应用服务中实现了 php 中的 api。

我需要它来执行加载的脚本并且它滞后,然后在调用它的一分钟内返回 500 错误

我需要你编写一个脚本,该脚本会进行大量的 http 调用、计算并最终将结果发送到数据库。脚本(需要 15 分钟到 2 小时)取决于您的输入,代码如下:

public function get() {

        $params = http_build_query($this->request['params']);

        /* -- start script --

         script takes 15 min to 2 hours depending on input $ params
         I need the script to finish before the http call dies 
       */

          $meli = new Meli;
          $meli -> data_extractor($params);

        /* -- end script -- */

        $this->response = array('Response' => ' script has started working');
        $this->responseStatus = 200;
    } 

我遇到的问题是,当我在调用它几分钟后调用 api 时,它在没有完成脚本的情况下返回 500 错误。

标签: phpapiasynchronous

解决方案


推荐阅读