source: admin/WebConsole/includes/restfunctions.php @ ebee36c

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 ebee36c was 8c9fcb2, checked in by ramon <ramongomez@…>, 9 years ago

#718: Integrar sondeo de estados de antios servicios de cliente y de nuevo OGAdent.

git-svn-id: https://opengnsys.es/svn/branches/version1.1@4835 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 
31    // post?
32    if (is_array($d)) {
33      if (!empty($d['post'])) {
34        curl_setopt($curly[$id], CURLOPT_POST,       1);
35        curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']);
36      }
37    }
38
39    // extra options?
40    if (!empty($options)) {
41      curl_setopt_array($curly[$id], $options);
42    }
43 
44    curl_multi_add_handle($mh, $curly[$id]);
45  }
46 
47  // execute the handles
48  $running = null;
49  do {
50    curl_multi_exec($mh, $running);
51  } while($running > 0);
52 
53 
54  // get content and remove handles
55  foreach($curly as $id => $c) {
56    $result[$id] = curl_multi_getcontent($c);
57    curl_multi_remove_handle($mh, $c);
58  }
59
60 // all done
61  curl_multi_close($mh);
62 
63  return $result;
64}
65 
66?>
67
Note: See TracBrowser for help on using the repository browser.