/** * Execute cURL call * * @param string $action Action to execute * @param array|null $data Data to attach to the execution * * @return mixed Result of the cURL call */ public static function executeCurl($action, array $data = null) { $ch = curl_init(); if ($ch === false) { throw new TelegramException('Curl failed to initialize'); } $curlConfig = [CURLOPT_URL => 'https://api.telegram.org/bot' . self::$telegram->getApiKey() . '/' . $action, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_SAFE_UPLOAD => true]; if (!empty($data)) { $curlConfig[CURLOPT_POSTFIELDS] = $data; } if (self::$telegram->getLogVerbosity() >= 3) { $curlConfig[CURLOPT_VERBOSE] = true; $verbose = fopen('php://temp', 'w+'); curl_setopt($ch, CURLOPT_STDERR, $verbose); } curl_setopt_array($ch, $curlConfig); $result = curl_exec($ch); //Logging curl requests if (self::$telegram->getLogVerbosity() >= 3) { rewind($verbose); $verboseLog = stream_get_contents($verbose); self::log('Verbose curl output:' . "\n" . htmlspecialchars($verboseLog) . "\n"); } //Logging getUpdates Update //Logging curl updates if ($action == 'getUpdates' & self::$telegram->getLogVerbosity() >= 1 | self::$telegram->getLogVerbosity() >= 3) { self::setInputRaw($result); self::log($result); } if ($result === false) { throw new TelegramException(curl_error($ch), curl_errno($ch)); } if (empty($result) | is_null($result)) { throw new TelegramException('Empty server response'); } curl_close($ch); return $result; }