source: admin/WebConsole/includes/restfunctions.php @ 83b9c80

918-git-images-111dconfigfileconfigure-oglivegit-imageslgromero-new-oglivemainmaint-cronmount-efivarfsmultivmmultivm-ogboot-installerogClonningEngineogboot-installer-jenkinsoglive-ipv6test-python-scriptsticket-301ticket-50ticket-50-oldticket-577ticket-585ticket-611ticket-612ticket-693ticket-700ubu24tplunification2use-local-agent-oglivevarios-instalacionwebconsole3
Last change on this file since 83b9c80 was ba3c59d, checked in by ramon <ramongomez@…>, 9 years ago

#739: Corregir errata y establecer timeout para peticiones REST en sondeo de estado.

git-svn-id: https://opengnsys.es/svn/branches/version1.1@4839 a21b9725-9963-47de-94b9-378ad31fedc9

  • Property mode set to 100644
File size: 1.4 KB
Line 
1<?php
2 
3/*
4 * Function: multiRequest.
5 * Params:   urls array, cURL options array.
6 * Returns:  array with JSON requests.
7 * Date:     2015-10-14
8 */
9function multiRequest($data, $options = array()) {
10 
11  // array of curl handles
12  $curly = array();
13  // data to be returned
14  $result = array();
15 
16  // multi handle
17  $mh = curl_multi_init();
18 
19  // loop through $data and create curl handles
20  // then add them to the multi-handle
21  foreach ($data as $id => $d) {
22 
23
24    $curly[$id] = curl_init();
25 
26    $url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
27    curl_setopt($curly[$id], CURLOPT_URL, $url);
28    curl_setopt($curly[$id], CURLOPT_HEADER, 0);
29    curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);
30    curl_setopt($curly[$id], CURLOPT_TIMEOUT, 1000);
31 
32    // post?
33    if (is_array($d)) {
34      if (!empty($d['post'])) {
35        curl_setopt($curly[$id], CURLOPT_POST, 1);
36        curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']);
37      }
38    }
39
40    // extra options?
41    if (!empty($options)) {
42      curl_setopt_array($curly[$id], $options);
43    }
44 
45    curl_multi_add_handle($mh, $curly[$id]);
46  }
47 
48  // execute the handles
49  $running = null;
50  do {
51    curl_multi_exec($mh, $running);
52  } while($running > 0);
53 
54 
55  // get content and remove handles
56  foreach($curly as $id => $c) {
57    $result[$id] = curl_multi_getcontent($c);
58    curl_multi_remove_handle($mh, $c);
59  }
60
61 // all done
62  curl_multi_close($mh);
63 
64  return $result;
65}
66 
67?>
68
Note: See TracBrowser for help on using the repository browser.