mirror of https://github.com/supernets/LibreY.git
fix: gateway timeout on calling fallback instances (merge pull request #16 from davidovski/fix_fallback)
Fix Gateway Timeout on fallback
This commit is contained in:
commit
82ac92a98b
5
api.php
5
api.php
|
@ -26,7 +26,10 @@
|
|||
switch ($type)
|
||||
{
|
||||
case 0:
|
||||
require "engines/google/text.php";
|
||||
$engine=$config->preferred_engines['text'];
|
||||
if (is_null($engine))
|
||||
$engine = "google";
|
||||
require "engines/$engine/text.php";
|
||||
$results = get_text_results($query, $page);
|
||||
break;
|
||||
case 1:
|
||||
|
|
|
@ -72,6 +72,13 @@
|
|||
curl_multi_exec($mh, $running);
|
||||
} while ($running);
|
||||
|
||||
if (curl_getinfo($google_ch)['http_code'] != '200')
|
||||
{
|
||||
require "engines/librex/text.php";
|
||||
return get_librex_results($query, $page);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($special_search != 0)
|
||||
{
|
||||
|
|
|
@ -169,6 +169,9 @@
|
|||
function print_text_results($results)
|
||||
{
|
||||
|
||||
if (empty($results))
|
||||
return;
|
||||
|
||||
$special = $results[0];
|
||||
|
||||
if (array_key_exists("did_you_mean", $special))
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
{
|
||||
global $config;
|
||||
|
||||
if (isset($_REQUEST["nfb"]) && $_REQUEST["nfb"] == "1")
|
||||
return array();
|
||||
|
||||
if (!$config->instance_fallback)
|
||||
return array();
|
||||
|
||||
|
@ -24,16 +27,12 @@
|
|||
do {
|
||||
$tries++;
|
||||
|
||||
// after "too many" requests, give up
|
||||
if ($tries > 5)
|
||||
return array();
|
||||
|
||||
$instance = array_pop($instances);
|
||||
|
||||
if (parse_url($instance)["host"] == parse_url($_SERVER['HTTP_HOST'])["host"])
|
||||
continue;
|
||||
|
||||
$url = $instance . "api.php?q=$query_encoded&p=$page&t=0";
|
||||
$url = $instance . "api.php?q=$query_encoded&p=$page&t=0&nfb=1";
|
||||
|
||||
$librex_ch = curl_init($url);
|
||||
curl_setopt_array($librex_ch, $config->curl_settings);
|
||||
|
@ -44,7 +43,10 @@
|
|||
$code = curl_getinfo($librex_ch)["http_code"];
|
||||
$results = json_decode($response, true);
|
||||
|
||||
} while ( $results == null || count($results) <= 1);
|
||||
} while ( !empty($instances) && ($results == null || count($results) <= 1));
|
||||
|
||||
if (empty($instances))
|
||||
return array();
|
||||
|
||||
return array_values($results);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue