php - fastest way to check web-services availability -


my application uses 70 external services. on init function want test if of them avaliable , can produce json. trying via curl, via parallel curl, if service unavaliable have wait timeout (5 sec) in worst case script hang 70 * 5 seconds not init function in application. maybe have better idea?

my code strict curl:

foreach ($services $key => $value) {   $url = $value['url'] . '?f=json';   $curl = curl_init();   curl_setopt($ch, curlopt_timeout, 5);   curl_setopt($ch, curlopt_returntransfer, 1);   curl_setopt($ch, curlopt_useragent, 'mozilla/5.0 (windows; u; windows nt 6.1; en-us; rv:1.9.1.2) gecko/20090729 firefox/3.5.2 gtb5');   curl_setopt($curl, curlopt_url, $url);    $result = curl_exec($curl);   $result2 = json_decode($results, true);    if ($result != false && gettype($result) !== "integer"       && !array_key_exists('error', $result)) {          $avaliableservices[$key] = true;    } } 

i trying modify timeout value, 5sec optimum value in example..

and same version of code parallel curl:

$i = 0; $running = null; $output = array(); $curlarray = array(); $master = curl_multi_init();   ($i = 0; $i < $length; $i++) {   $curlarray[$i] = curl_init($urlarray[$i]);   curl_setopt($curlarray[$i], curlopt_timeout, 5);   curl_setopt($curlarray[$i], curlopt_returntransfer, 1);   curl_setopt($curlarray[$i], curlopt_useragent, 'mozilla/5.0 (windows; u; windows nt 6.1; en-us; rv:1.9.1.2) gecko/20090729 firefox/3.5.2 gtb5');    curl_multi_add_handle($master, $curlarray[$i]); }  {   curl_multi_exec($master, $running); } while($running > 0);  foreach ($curlarray $key => $value) {   $result = curl_multi_getcontent($value);   $result2 = json_decode($results, true);    if ($result != false && gettype($result) !== "integer"       && !array_key_exists('error', $result)) {              $avaliableservices[$key] = true;   } } 

i'm wondering if there fastest way?


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -