@@ -85,30 +85,26 @@ private function processStats(): void {
8585 'Accept: application/json ' ,
8686 ]);
8787
88- if (curl_errno ($ ch )) {
88+ $ response = curl_exec ($ ch );
89+
90+ if ($ response === false ) {
8991 $ error_message = 'cURL error: ' . curl_error ($ ch );
9092 $ this ->log_error ($ error_message );
9193 throw new Exception ($ error_message );
9294 }
9395
9496 // Get HTTP status code
95- $ http_code = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
97+ $ http_code = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
98+ $ header_size = curl_getinfo ($ ch , CURLINFO_HEADER_SIZE );
99+
96100 if ($ http_code !== 200 ) {
97101 $ error_message = "HTTP $ http_code " ;
98102 $ this ->log_error ($ error_message );
99103 throw new Exception ($ error_message );
100104 }
101105
102- $ response = curl_exec ($ ch );
103- if ($ response === false ) {
104- $ error_message = 'cURL error: ' . curl_error ($ ch );
105- $ this ->log_error ($ error_message );
106- throw new Exception ($ error_message );
107- }
108-
109106 /** @var string $response */
110- $ header_size = curl_getinfo ($ ch , CURLINFO_HEADER_SIZE );
111- $ api_data = substr ($ response , $ header_size );
107+ $ api_data = substr ($ response , $ header_size );
112108
113109 curl_close ($ ch );
114110
0 commit comments