equal
deleted
inserted
replaced
58 } |
58 } |
59 else{ |
59 else{ |
60 return WikiTagUtils::returnNullResult(null); |
60 return WikiTagUtils::returnNullResult(null); |
61 } |
61 } |
62 |
62 |
63 $ar = WikiTagUtils::requestWikipedia($params); |
63 try { |
|
64 $ar = WikiTagUtils::requestWikipedia($params); |
|
65 } |
|
66 catch (\Exception $e){ |
|
67 throw new \Exception($e->getMessage()); |
|
68 } |
64 $res = $ar[0]; |
69 $res = $ar[0]; |
65 $original_response = $res; |
70 $original_response = $res; |
66 $pages = $ar[1]; |
71 $pages = $ar[1]; |
67 // If there 0 or more than 1 result, the query has failed |
72 // If there 0 or more than 1 result, the query has failed |
68 if(count($pages)>1 || count($pages)==0){ |
73 if(count($pages)>1 || count($pages)==0){ |
170 |
175 |
171 $ch = curl_init(); |
176 $ch = curl_init(); |
172 curl_setopt($ch, CURLOPT_URL, $url); |
177 curl_setopt($ch, CURLOPT_URL, $url); |
173 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
178 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
174 curl_setopt($ch, CURLOPT_USERAGENT, 'http://www.iri.centrepompidou.fr'); |
179 curl_setopt($ch, CURLOPT_USERAGENT, 'http://www.iri.centrepompidou.fr'); |
|
180 curl_setopt($ch, CURLOPT_TIMEOUT_MS, 5000); |
175 $res = curl_exec($ch); |
181 $res = curl_exec($ch); |
|
182 $curl_errno = curl_errno($ch); |
|
183 $curl_error = curl_error($ch); |
176 curl_close($ch); |
184 curl_close($ch); |
|
185 |
|
186 if ($curl_errno > 0) { |
|
187 throw new \Exception("Wikipedia request failed. cURLError #$curl_errno: $curl_error\n"); |
|
188 } |
177 |
189 |
178 $val = json_decode($res, true); |
190 $val = json_decode($res, true); |
179 $pages = $val["query"]["pages"]; |
191 $pages = $val["query"]["pages"]; |
180 return array($res, $pages); |
192 return array($res, $pages); |
181 } |
193 } |