简体   繁体   English

Telegram php bot:长脚本执行会冻结 bot

[英]Telegram php bot: long script execution freezes the bot

I'm creating a Telegram bot using PHP, and I've deployed the script to heroku.com.我正在使用 PHP 创建一个 Telegram bot,并将脚本部署到 heroku.com。 Some of the commands of the bot may take more time to execute, due to while loop cycling through a big database.由于 while 循环在大型数据库中循环,bot 的某些命令可能需要更多时间来执行。 When the script runs for more than 30 seconds, it freezes and no commands work anymore.当脚本运行超过 30 秒时,它会冻结并且命令不再起作用。 I have to re-deploy the script, deleting the part of code which takes longer to complete, in order to restore the bot.我必须重新部署脚本,删除需要更长时间才能完成的代码部分,以恢复机器人。

Is there a limit of execution time imposed by Telegram APIs? Telegram API 是否有执行时间限制? And is there a way to extend this limit to more than one minute?有没有办法将此限制扩展到一分钟以上?

Thanks for the help谢谢您的帮助

You're going to have to build a workaround with background processes.您将不得不使用后台进程构建解决方法。 This is likely a time limit on heroku, not the Telegram API.这可能是 heroku 的时间限制,而不是 Telegram API。

The timeout value is not configurable.超时值不可配置。 If your server requires longer than 30 seconds to complete a given request, we recommend moving that work to a background task or worker to periodically ping your server to see if the processing request has been finished.如果您的服务器需要超过 30 秒来完成给定的请求,我们建议将该工作移至后台任务或工作人员以定期 ping 您的服务器以查看处理请求是否已完成。

https://devcenter.heroku.com/articles/request-timeout https://devcenter.heroku.com/articles/request-timeout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM