在执行60秒后由Webhook遇到“读取超时过期”错误
问题描述:
最近我遇到了一个电报bot api的问题,我之前没有过......我使用Webhook连接方法来捕获bot请求并用PHP重新编程脚本,有时触发的脚本需要一分多钟才能完成处理。大约一个月前,一切正常,电报僵尸等待足够长的脚本完全执行,但现在我的连接暂停,并通过电报api“读取超时过期”后60秒执行,然后它尝试相同的即时通讯Webhook错误请求再次,这些继续下去,直到我的服务器负载过多打开条目...我已经尝试connection-handling尽管它似乎没用,因为我的连接不是浏览器端。我意识到它应该与Webhook的设置本身有关,但我不知道它有什么想法?在执行60秒后由Webhook遇到“读取超时过期”错误
这里的东西,可以给你的身影:
我的代码:
<?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秒后到我的网络挂接的状态响应:
{ “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}}
答
这是我放在脚本顶部的代码。它响应电报,以便它们停止等待,脚本继续处理。
<?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();
}
欢迎来到SO!请查看以下文章并适当地更新问题: https://stackoverflow.com/help/how-to-ask – garfbradaz
hey garfbradaz,tnx!无论如何,我确实已经阅读过这本手册,并试图写下我的帖子,但无论如何,我都是新手......你能更具体吗? –
嗨@Samuel - 请发布一些你已经尝试过的例子代码,并且遇到任何错误。它有助于表明你试图解决问题,以及你做错了什么。祝你好运,享受SO社区。 – garfbradaz