Utils/WikiTagUtils.php
changeset 50 e967654e90cb
parent 43 54f204bceb28
child 60 984ba20c150b
--- a/Utils/WikiTagUtils.php	Mon Nov 28 15:58:34 2011 +0100
+++ b/Utils/WikiTagUtils.php	Wed Nov 30 17:58:18 2011 +0100
@@ -60,7 +60,12 @@
             return WikiTagUtils::returnNullResult(null);
         }
         
-        $ar = WikiTagUtils::requestWikipedia($params);
+        try {
+            $ar = WikiTagUtils::requestWikipedia($params);
+        }
+        catch (\Exception $e){
+            throw new \Exception($e->getMessage());
+        }
         $res = $ar[0];
         $original_response = $res;
         $pages = $ar[1];
@@ -172,9 +177,16 @@
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_USERAGENT, 'http://www.iri.centrepompidou.fr');
+        curl_setopt($ch, CURLOPT_TIMEOUT_MS, 5000);
         $res = curl_exec($ch);
+        $curl_errno = curl_errno($ch);
+        $curl_error = curl_error($ch);
         curl_close($ch);
         
+        if ($curl_errno > 0) {
+            throw new \Exception("Wikipedia request failed. cURLError #$curl_errno: $curl_error\n");
+        }
+        
         $val = json_decode($res, true);
         $pages = $val["query"]["pages"];
         return array($res, $pages);