遇到“读取超时已过期"执行 60 秒后 Webhook 出错

遇到“读取超时已过期

问题描述:

最近我遇到了一个我以前没有遇到过的电报机器人 API 问题...我使用 Webhook 连接方法来捕获机器人请求并使用 PHP 脚本重新发送,有时触发的脚本需要超过一分钟才能完成处理.大约一个月前,一切正常,电报机器人等待脚本完全执行的时间足够长,但现在我的连接挂起,我在 60 秒执行后通过电报 API读取超时过期"收到此 Webhook 错误,然后尝试相同再次请求,这些一直持续到我的服务器因打开的条目过多而过载...我已经尝试过 连接-处理 虽然它似乎没用,因为我的连接不是浏览器端.我意识到它应该与 Webhook 的设置本身有关,但我无法弄清楚......有什么想法吗?

lately Im facing a problem with telegram bot api which i haven't had before... Im using Webhook method of connection to catch bot requests and respoding with PHP script and sometimes the triggered script takes more than a minute to finish processing. about a month ago everything was working fine and telegram bot wait long enough for script to completely execute, but now my connection suspend and im getting this Webhook error through telegram api "Read timeout expired" after 60 Seconds of execution and then it attempt the same request again and these goes on and on until my server overloads with too many open entries... i already tried connection-handling although it seemed useless since my connection is not browser-end. i realize it should have something to do with Webhook's setting itself but i cant figure it out... any ideas?

这里有一些东西可以给你这个数字:

Here is something that could give you the figure:

我的代码:

<?php

...running hundreds of thousands of multi-curl requests that take 10 min for example
...or/ sleep(61);
...or/ basically anything that takes more than 60 seconds to run

?>

运行上述脚本 60 秒后,Telegram 对 Webhook 状态的响应:

Telegram's response to my Webhook's state after 60 seconds of running the above script:

{"ok":true,"result":{"url":"https://????.com/??.php","has_custom_certificate":false,"pending_update_count":1,"last_error_date":1499351442,"last_error_message":"读取超时已过期","max_connections":40}}

{"ok":true,"result":{"url":"https://????.com/??.php","has_custom_certificate":false,"pending_update_count":1,"last_error_date":1499351442,"last_error_message":"Read timeout expired","max_connections":40}}

这是我放在脚本顶部的代码.它响应电报,所以他们停止等待,脚本继续处理.

this is the code I put at the top of my scripts. it responds to telegram so they stop waiting, and the scripts continues processing.

<?php
    set_time_limit(0);
    ignore_user_abort(true);
    $out =  json_encode([
      'method'=>'sendMessage',
      'chat_id'=>$my_chat_id,
      'text'=> "Starting process..."
      ]);   
    echo $out;
    header('Connection: close');
    header('Content-Length: '.strlen($out));
    header("Content-type:application/json");
    flush();
    if (function_exists('fastcgi_finish_request')) {
        fastcgi_finish_request();
    }