From 258ab74f474096ffc14f4779a1c6baba0a612efd Mon Sep 17 00:00:00 2001 From: GlazerMann Date: Wed, 31 Jan 2024 20:35:49 -0600 Subject: [PATCH] Reuse CrossRef CURL object --- expandFns.php | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/expandFns.php b/expandFns.php index e9f5e710a6..6dd93c653f 100644 --- a/expandFns.php +++ b/expandFns.php @@ -107,17 +107,16 @@ function doi_works(string $doi) : ?bool { } function is_doi_active(string $doi) : ?bool { + static $ch = NULL; + if ($ch === NULL) { + $ch = curl_init_array(1.0,[ + CURLOPT_HEADER => TRUE, + CURLOPT_NOBODY => TRUE, + CURLOPT_USERAGENT => BOT_CROSSREF_USER_AGENT]); + } $doi = trim($doi); $url = "https://api.crossref.org/v1/works/" . doi_encode($doi) . "?mailto=".CROSSREFUSERNAME; // do not encode crossref email - $ch = curl_init_array(1.0,[ - CURLOPT_HEADER => TRUE, - CURLOPT_NOBODY => TRUE, - CURLOPT_SSL_VERIFYHOST => 0, - CURLOPT_SSL_VERIFYPEER => FALSE, - CURLOPT_SSL_VERIFYSTATUS => FALSE, - CURLOPT_USERAGENT => BOT_CROSSREF_USER_AGENT, - CURLOPT_URL => $url - ]); + curl_setopt($ch, CURLOPT_URL, $url); $headers_test = @curl_exec($ch); if ($headers_test === FALSE || (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) === 503)) { sleep(4);