Try different instance if fallback fails
This commit is contained in:
parent
eecaae4a03
commit
feef1f4525
|
@ -10,18 +10,23 @@
|
|||
|
||||
$instances_json = json_decode(file_get_contents("instances.json"), true);
|
||||
$instances = array_map(fn($n) => $n['clearnet'], array_filter($instances_json['instances'], fn($n) => !is_null($n['clearnet'])));
|
||||
$instance = $instances[array_rand($instances)];
|
||||
|
||||
$query_encoded = urlencode($query);
|
||||
|
||||
// TODO add all the required options
|
||||
$url = $instance . "api.php?q=$query_encoded&p=$page&t=0";
|
||||
$results = array();
|
||||
|
||||
$librex_ch = curl_init($url);
|
||||
curl_setopt_array($librex_ch, $config->curl_settings);
|
||||
$response = curl_exec($librex_ch);
|
||||
curl_close($librex_ch);
|
||||
do {
|
||||
$instance = $instances[array_rand($instances)];
|
||||
$url = $instance . "api.php?q=$query_encoded&p=$page&t=0";
|
||||
|
||||
return array_values(json_decode($response, true));
|
||||
$librex_ch = curl_init($url);
|
||||
curl_setopt_array($librex_ch, $config->curl_settings);
|
||||
$response = curl_exec($librex_ch);
|
||||
curl_close($librex_ch);
|
||||
$code = curl_getinfo($librex_ch)["http_code"];
|
||||
$results = json_decode($response, true);
|
||||
|
||||
} while ( $results == null || empty($results));
|
||||
|
||||
return array_values($results);
|
||||
}
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue