Commit 8dfd91cf authored by Dominik Hebeler's avatar Dominik Hebeler
Browse files

Timeout für alle Abfragen aus den Quictips eingeführt (2s)

Wikipedia läuft in einen Timeout- Vermutlich wurden wir gebannt.
Die Ursache konnte ich nicht beheben, aber den resultierenden Fehler.
parent 6aeb31ec
......@@ -172,7 +172,12 @@ class MetaGerSearch extends Controller
# Wikipedia Quicktip
$url = "https://" . APP::getLocale() . ".wikipedia.org/w/api.php?action=opensearch&search=" . urlencode($q) . "&limit=10&namespace=0&format=json&redirects=resolve";
$decodedResponse = json_decode($this->get($url), true);
try{
$content = $this->get($url);
}catch(\ErrorException $e){
$content = "";
}
$decodedResponse = json_decode($content, true);
if (isset($decodedResponse[1][0]) && isset($decodedResponse[2][0]) && isset($decodedResponse[3][0])) {
$quicktip = [];
$firstSummary = $decodedResponse[2][0];
......@@ -261,7 +266,8 @@ class MetaGerSearch extends Controller
public function get($url)
{
return file_get_contents($url);
$ctx = stream_context_create(array('http'=>array('timeout' => 2,)));
return file_get_contents($url, false, $ctx);
}
private function startsWith($haystack, $needle)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment