curl - Speed up Telegram Bot API in PHP -


i have used php in order write telegram bot uses webhook means php file called each update. have used curl in order post json https://api.telegram.org. when send message in php file, responds in around 1 second. think because not reuse curl connection. connection closes after php file finishes.

i have written java application calls getupdate method every 5 seconds. responds in around 500 milliseconds because reuses connection.

how can speed php bot java application? there way reuse connection when php file finished , php file run?

here php code:

function post($method, $data) {     $url = "https://api.telegram.org/bot".$authenticationtoken."/".$method;     $curl = curl_init();     curl_setopt($curl, curlopt_returntransfer, true);     curl_setopt($curl, curlopt_customrequest, "post");     curl_setopt($curl, curlopt_post, true);     curl_setopt($curl, curlopt_postfields, json_encode($data));     curl_setopt($curl, curlopt_httpheader, array("content-type: application/json"));     curl_setopt($curl, curlopt_url, $url);     curl_setopt($curl, curlopt_encoding,  '');     $resultjson = curl_exec($curl);     curl_close($curl);      $result = json_decode($resultjson,true);     if(!$result["ok"])         logf($resultjson);     return $result; } 

p.s: ping time of url around 200 milliseconds.


Comments