Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
2 merge requests!870Development,!869Timeout für alle Abfragen aus den Quictips eingeführt (2s)
...@@ -172,7 +172,12 @@ class MetaGerSearch extends Controller ...@@ -172,7 +172,12 @@ class MetaGerSearch extends Controller
# Wikipedia Quicktip # Wikipedia Quicktip
$url = "https://" . APP::getLocale() . ".wikipedia.org/w/api.php?action=opensearch&search=" . urlencode($q) . "&limit=10&namespace=0&format=json&redirects=resolve"; $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])) { if (isset($decodedResponse[1][0]) && isset($decodedResponse[2][0]) && isset($decodedResponse[3][0])) {
$quicktip = []; $quicktip = [];
$firstSummary = $decodedResponse[2][0]; $firstSummary = $decodedResponse[2][0];
...@@ -261,7 +266,8 @@ class MetaGerSearch extends Controller ...@@ -261,7 +266,8 @@ class MetaGerSearch extends Controller
public function get($url) 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) private function startsWith($haystack, $needle)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment