From 1605f21e4f6c10bfa59683c332709a1358b19dd5 Mon Sep 17 00:00:00 2001 From: GlazerMann Date: Wed, 31 Jan 2024 17:07:33 -0600 Subject: [PATCH] Reduce re-init (#4394) --- WikipediaBot.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/WikipediaBot.php b/WikipediaBot.php index 876da8ad40..031bda332f 100644 --- a/WikipediaBot.php +++ b/WikipediaBot.php @@ -18,7 +18,7 @@ final class WikipediaBot { private Consumer $user_consumer; private Client $user_client; private Token $user_token; - private static CurlHandle $ch_login; + private static CurlHandle $ch_write; private static CurlHandle $ch_logout; private string $the_user = ''; private static ?self $last_WikipediaBot; // For NonStandardMode() @@ -28,7 +28,10 @@ public static function make_ch() : void { if ($init_done) return; $init_done = TRUE; // This is a little paranoid - see https://curl.se/libcurl/c/CURLOPT_FAILONERROR.html - self::$ch_login = curl_init_array(1.0, [CURLOPT_FAILONERROR => TRUE ]); + self::$ch_write = curl_init_array(1.0, + [CURLOPT_FAILONERROR => TRUE, + CURLOPT_POST => TRUE, + CURLOPT_URL => API_ROOT]); self::$ch_logout = curl_init_array(1.0, [CURLOPT_FAILONERROR => TRUE ]); } @@ -115,14 +118,12 @@ private function fetch(array $params, int $depth = 1) : ?object { $authenticationHeader = $request->toHeader(); try { - curl_setopt_array(self::$ch_login, [ - CURLOPT_POST => TRUE, + curl_setopt_array(self::$ch_write, [ CURLOPT_POSTFIELDS => http_build_query($params), CURLOPT_HTTPHEADER => [$authenticationHeader], - CURLOPT_URL => API_ROOT ]); - $data = (string) @curl_exec(self::$ch_login); + $data = (string) @curl_exec(self::$ch_write); $ret = @json_decode($data); if (($ret === NULL) || ($ret === FALSE) || (isset($ret->error) && ( // @codeCoverageIgnoreStart (string) $ret->error->code === 'assertuserfailed' ||