Skip to content

Commit

Permalink
Reuse CrossRef CURL object
Browse files Browse the repository at this point in the history
  • Loading branch information
GlazerMann authored Feb 1, 2024
1 parent 1b90f27 commit 258ab74
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions expandFns.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 258ab74

Please sign in to comment.