I have several Telegram bots working nice for years; I used 2 ways to send requests to Bot API:
The first is:
file_get_contents($url);
The second is:
$ch = curl_init($url);
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_TIMEOUT => 60
]);
curl_exec($ch);
Some days ago I noticed that:
file_get_contents()
stopped working completely returningfailed to open stream: Connection timed out
every time, but it works nice with requests to other websites;- cURL keeps working, but very slow: after I send a message to the bot, I wait 5-8 seconds to receive the answer; when I changed
CURLOPT_CONNECTTIMEOUT
to1
the waiting period reduced to 1 second or so.
file_get_contents()
has started working as before with this context
:
file_get_contents($url, false, stream_context_create([
'socket' => [
'bindto' => '0:0'
]
]));
The last_error_message
is always Read timeout expired
. Server reboot does not help. Direct requests to Bot API from a browser works perfectly.
What is happening and how to fix it?