I'm creating a highload Telegram Bot, which means many requests come in and they take time to handle.
I use webhook (Telegram sends updates to, say, handler.php
) which requires to respond with correct []
answer and fully close the connection for Telegram to send the next update. Otherwise Telegram will only increase pending_update_count
and won't send any new updates until the previous one is handled.
So what I'm trying to do is to respond correctly and close the connection before code is executed.
StackOverflow suggests some solutions. But none of these will work for me because they only close the connection if there was no output and I need to respond with []
.
How do I close a connection early?
Send response and continue executing script - PHP
The only workaround I came up with is to call shell_exec('php sendMessage.php >/dev/null 2>/dev/null &')
from handler.php
. Works perfectly well but that's not what I need. Any other suggestions to respond and close the connection, so code can execute in the background?