diff --git a/WikipediaBot.php b/WikipediaBot.php index e09133adc1..f9b43f7646 100644 --- a/WikipediaBot.php +++ b/WikipediaBot.php @@ -18,7 +18,8 @@ final class WikipediaBot { private Consumer $user_consumer; private Client $user_client; private Token $user_token; - private static CurlHandle $ch; // All wikipedia connections share a session + private static CurlHandle $ch_login; + private static CurlHandle $ch_logout; private string $the_user = ''; private static ?self $last_WikipediaBot; // For NonStandardMode() @@ -26,8 +27,9 @@ public static function make_ch() : void { static $init_done = FALSE; if ($init_done) return; $init_done = TRUE; - self::$ch = curl_init_array(1.0, - [CURLOPT_FAILONERROR => TRUE ]); // This is a little paranoid - see https://curl.se/libcurl/c/CURLOPT_FAILONERROR.html + // 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_logout = curl_init_array(1.0, [CURLOPT_FAILONERROR => TRUE ]); } function __construct() { @@ -113,14 +115,14 @@ private function fetch(array $params, int $depth = 1) : ?object { $authenticationHeader = $request->toHeader(); try { - curl_setopt_array(self::$ch, [ + curl_setopt_array(self::$ch_login, [ CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => http_build_query($params), CURLOPT_HTTPHEADER => [$authenticationHeader], CURLOPT_URL => API_ROOT ]); - $data = (string) @curl_exec(self::$ch); + $data = (string) @curl_exec(self::$ch_login); $ret = @json_decode($data); if (($ret === NULL) || ($ret === FALSE) || (isset($ret->error) && ( // @codeCoverageIgnoreStart (string) $ret->error->code === 'assertuserfailed' || @@ -363,17 +365,17 @@ static private function QueryAPI(array $params) : string { try { $params['format'] = 'json'; - curl_setopt_array(self::$ch, [ + curl_setopt_array(self::$ch_logout, [ CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => http_build_query($params), CURLOPT_HTTPHEADER => [], CURLOPT_URL => API_ROOT, ]); - $data = (string) @curl_exec(self::$ch); + $data = (string) @curl_exec(self::$ch_logout); if ($data === '') { sleep(4); // @codeCoverageIgnore - $data = (string) @curl_exec(self::$ch); // @codeCoverageIgnore + $data = (string) @curl_exec(self::$ch_logout); // @codeCoverageIgnore } return (self::ret_okay(@json_decode($data))) ? $data : ''; // @codeCoverageIgnoreStart @@ -401,11 +403,11 @@ static public function get_links(string $title) : string { } static public function GetAPage(string $title) : string { - curl_setopt_array(self::$ch, + curl_setopt_array(self::$ch_logout, [CURLOPT_HTTPGET => TRUE, CURLOPT_HTTPHEADER => [], CURLOPT_URL => WIKI_ROOT . '?' . http_build_query(['title' => $title, 'action' =>'raw'])]); - $text = (string) @curl_exec(self::$ch); + $text = (string) @curl_exec(self::$ch_logout); return $text; }