dermestid / bold-phylodiv-scripts

Scripts to calculate phylodiversity and its distribution from BOLD DNA barcode data.
1 stars 0 forks source link

Extend timeout for initial query to BOLD #142

Open dermestid opened 3 years ago

dermestid commented 3 years ago

in get_bold_record_count, the call file_get_contents(bold url) can timeout, causing an HTTP failure and an ungraceful crash. This generally only happens if asking BOLD to count entries in a super huge phylum (e.g. Arthropoda)

Fix the timeout by adding longer timeout in the context to the request:

$context = stream_context_create([
    'http' => ['timeout' => 300] // 5 minutes for BOLD to respond - should be long enough to count biggest phyla
]);
$bold_response = json_decode(file_get_contents($bold_query, false, $context), true);

And additionally respond better to other HTTP failures (although this isn't strictly necessary as the SSE communication to client is closed properly even on crash).