source: admin/WebConsole/includes/restfunctions.php @ 03e3f88

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-instalacion
Last change on this file since 03e3f88 was 1d380e5, checked in by OpenGnSys Support Team <soporte-og@…>, 6 years ago

#915 Adapt web to use the new run/schedule cmd in REST API

This patch implements run/schedule in the set of available PHP functions.
It also replaces old SocketHidra? commands by run/schedule in
gestor_colasacciones.php and gestor_ejecutaracciones.php.

  • Property mode set to 100644
File size: 16.7 KB
Line 
1
2<?php
3
4define('OG_REST_URL', 'http://127.0.0.1:8888/');
5
6define('GET', 1);
7define('POST', 2);
8define('CUSTOM', 3);
9
10define('OG_REST_CMD_CLIENTS', 'clients');
11define('OG_REST_CMD_WOL', 'wol');
12define('OG_REST_CMD_SESSION', 'session');
13define('OG_REST_CMD_RUN', 'shell/run');
14define('OG_REST_CMD_OUTPUT', 'shell/output');
15define('OG_REST_CMD_POWEROFF', 'poweroff');
16define('OG_REST_CMD_REBOOT', 'reboot');
17define('OG_REST_CMD_STOP', 'stop');
18define('OG_REST_CMD_REFRESH', 'refresh');
19define('OG_REST_CMD_HARDWARE', 'hardware');
20define('OG_REST_CMD_SOFTWARE', 'software');
21define('OG_REST_CMD_CREATE_IMAGE', 'image/create');
22define('OG_REST_CMD_RESTORE_IMAGE', 'image/restore');
23define('OG_REST_CMD_SETUP', 'image/setup');
24define('OG_REST_CMD_CREATE_BASIC_IMAGE', 'image/create/basic');
25define('OG_REST_CMD_CREATE_INCREMENTAL_IMAGE', 'image/create/incremental');
26define('OG_REST_CMD_RESTORE_BASIC_IMAGE', 'image/restore/basic');
27define('OG_REST_CMD_RESTORE_INCREMENTAL_IMAGE', 'image/restore/incremental');
28define('OG_REST_CMD_RUN_SCHEDULE', 'run/schedule');
29
30define('OG_REST_PARAM_CLIENTS', 'clients');
31define('OG_REST_PARAM_ADDR', 'addr');
32define('OG_REST_PARAM_MAC', 'mac');
33define('OG_REST_PARAM_DISK', 'disk');
34define('OG_REST_PARAM_PART', 'partition');
35define('OG_REST_PARAM_RUN', 'run');
36define('OG_REST_PARAM_TYPE', 'type');
37define('OG_REST_PARAM_STATE', 'state');
38define('OG_REST_PARAM_NAME', 'name');
39define('OG_REST_PARAM_REPOS', 'repository');
40define('OG_REST_PARAM_ID', 'id');
41define('OG_REST_PARAM_CODE', 'code');
42define('OG_REST_PARAM_PROFILE', 'profile');
43define('OG_REST_PARAM_TYPE', 'type');
44define('OG_REST_PARAM_CACHE', 'cache');
45define('OG_REST_PARAM_CACHE_SIZE', 'cache_size');
46define('OG_REST_PARAM_CODE', 'code');
47define('OG_REST_PARAM_FILE_SYSTEM', 'filesystem');
48define('OG_REST_PARAM_SIZE', 'size');
49define('OG_REST_PARAM_FORMAT', 'format');
50define('OG_REST_PARAM_PARTITION_SETUP', 'partition_setup');
51define('OG_REST_PARAM_SYNC_PARAMS', 'sync_params');
52define('OG_REST_PARAM_SYNC', 'sync');
53define('OG_REST_PARAM_DIFF', 'diff');
54define('OG_REST_PARAM_REMOVE', 'remove');
55define('OG_REST_PARAM_COMPRESS', 'compress');
56define('OG_REST_PARAM_CLEANUP', 'cleanup');
57define('OG_REST_PARAM_CACHE', 'cache');
58define('OG_REST_PARAM_CLEANUP_CACHE', 'cleanup_cache');
59define('OG_REST_PARAM_REMOVE_DST', 'remove_dst');
60define('OG_REST_PARAM_PATH', 'path');
61define('OG_REST_PARAM_DIFF_ID', 'diff_id');
62define('OG_REST_PARAM_DIFF_NAME', 'diff_name');
63define('OG_REST_PARAM_METHOD', 'method');
64
65$conf_file = parse_ini_file(__DIR__ . '/../../etc/ogAdmServer.cfg');
66define('OG_REST_API_TOKEN', 'Authorization: ' . $conf_file['APITOKEN']);
67
68function common_request($command, $type, $data = null) {
69
70        $json = json_encode($data);
71
72        $service_url = OG_REST_URL.$command;
73
74        $curl = curl_init($service_url);
75        curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
76        curl_setopt($curl, CURLOPT_HTTPHEADER, array(
77                OG_REST_API_TOKEN,
78        ));
79
80        switch ($type) {
81                default:
82                case GET:
83                        break;
84                case POST:
85                        curl_setopt($curl, CURLOPT_POST, true);
86                        curl_setopt($curl, CURLOPT_POSTFIELDS, $json);
87        }
88
89        $curl_response = curl_exec($curl);
90        $info = curl_getinfo($curl);
91
92        if ($curl_response === false || $info['http_code'] != 200) {
93                syslog(LOG_ERR, 'error occured during curl exec. Additioanl info: ' . print_r($info, TRUE));
94                return 0;
95        }
96
97        curl_close($curl);
98
99        syslog(LOG_INFO, 'response '.$command.' ok!');
100
101        return json_decode($curl_response, true);
102}
103
104
105function shell($case, $string_ips, $command) {
106
107        $ips = explode(';',$string_ips);
108
109        switch ($case) {
110                case 1:
111                        $data = array(OG_REST_PARAM_CLIENTS => $ips,
112                                OG_REST_PARAM_RUN => $command);
113                        $command = OG_REST_CMD_RUN;
114                        break;
115                default:
116                case 2:
117                        $data = array(OG_REST_PARAM_CLIENTS => $ips);
118                        $command = OG_REST_CMD_OUTPUT;
119        }
120
121        $result = common_request($command, POST,
122                $data)[OG_REST_PARAM_CLIENTS][0]['output'];
123
124        return (is_null($result) ? '1' : $result);
125}
126
127function clients($case, $ips) {
128
129        switch ($case) {
130                case 1:
131                        $type = POST;
132                        $data = array(OG_REST_PARAM_CLIENTS => $ips);
133                        break;
134                case 2:
135                        $type = GET;
136                        $data = null;
137                        break;
138        }
139
140        $result = common_request(OG_REST_CMD_CLIENTS, $type, $data);
141
142        $trama_notificacion = "";
143        if (isset($result[OG_REST_PARAM_CLIENTS])) {
144                foreach ($result[OG_REST_PARAM_CLIENTS] as $client) {
145                        $trama_notificacion .= $client[OG_REST_PARAM_ADDR].'/'.
146                                $client[OG_REST_PARAM_STATE].';';
147                }
148        }
149
150        return $trama_notificacion;
151}
152
153function wol($type_wol, $macs, $ips) {
154
155        switch ($type_wol) {
156                default:
157                case 1:
158                        $wol = 'broadcast';
159                        break;
160                case 2:
161                        $wol = 'unicast';
162        }
163
164        $clients = array();
165
166        for($i=0; $i<count($macs); $i++) {
167                $clients[] = array(OG_REST_PARAM_ADDR => $ips[$i],
168                        OG_REST_PARAM_MAC => $macs[$i]);
169        }
170
171        $data = array(OG_REST_PARAM_TYPE => $wol,
172                OG_REST_PARAM_CLIENTS => $clients);
173
174        common_request(OG_REST_CMD_WOL, POST, $data);
175}
176
177function session($string_ips, $params) {
178
179        preg_match_all('!\d{1}!', $params, $matches);
180
181        $ips = explode(';',$string_ips);
182        $disk = $matches[0][0];
183        $part = $matches[0][1];
184
185        $data = array(OG_REST_PARAM_CLIENTS => $ips,
186                OG_REST_PARAM_DISK => $disk, OG_REST_PARAM_PART => $part);
187
188        common_request(OG_REST_CMD_SESSION, POST, $data);
189}
190
191function create_image($string_ips, $params) {
192
193        preg_match_all('/(?<=\=)(.*?)(?=\r)/', $params, $matches);
194
195        $ips = explode(';',$string_ips);
196        $disk = $matches[0][0];
197        $part = $matches[0][1];
198        $code = $matches[0][2];
199        $id = $matches[0][3];
200        $name = $matches[0][4];
201        $repos = $matches[0][5];
202
203        $data = array(OG_REST_PARAM_CLIENTS => $ips,
204                OG_REST_PARAM_DISK => $disk,
205                OG_REST_PARAM_PART => $part,
206                OG_REST_PARAM_CODE => $code,
207                OG_REST_PARAM_ID => $id,
208                OG_REST_PARAM_NAME => $name,
209                OG_REST_PARAM_REPOS => $repos);
210
211        common_request(OG_REST_CMD_CREATE_IMAGE, POST, $data);
212}
213
214function restore_image($string_ips, $params) {
215
216        preg_match_all('/(?<=\=)(.*?)(?=\r)/', $params, $matches);
217
218        $ips = explode(';',$string_ips);
219        $disk = $matches[0][0];
220        $part = $matches[0][1];
221        $image_id = $matches[0][2];
222        $name = $matches[0][3];
223        $repos = $matches[0][4];
224        $profile = $matches[0][5];
225        $type = $matches[0][6];
226
227        $data = array(OG_REST_PARAM_DISK => $disk, OG_REST_PARAM_PART => $part,
228                OG_REST_PARAM_ID => $image_id, OG_REST_PARAM_NAME => $name,
229                OG_REST_PARAM_REPOS => $repos,
230                OG_REST_PARAM_PROFILE => $profile,
231                OG_REST_PARAM_TYPE => $type,
232                OG_REST_PARAM_CLIENTS => $ips);
233
234        common_request(OG_REST_CMD_RESTORE_IMAGE, POST, $data);
235}
236
237function create_basic_image($string_ips, $params) {
238
239        preg_match_all('/(?<=\=)[^\r]*(?=\r)?/', $params, $matches);
240
241        $ips = explode(';',$string_ips);
242        $disk = $matches[0][0];
243        $part = $matches[0][1];
244        $code = $matches[0][2];
245        $image_id = $matches[0][3];
246        $name = $matches[0][4];
247        $repos = $matches[0][5];
248
249        $sync = $matches[0][7]; // Syncronization method
250
251        $diff = $matches[0][8]; // Send the whole file if there are differences
252        $remove = $matches[0][9]; // Delete files at destination that are not at source
253        $compress = $matches[0][10]; // Compress before sending
254
255        $cleanup = $matches[0][11]; // Delete image before creating it
256        $cache = $matches[0][12]; // Copy image to cache
257        $cleanup_cache = $matches[0][13]; // Delete image from cache before copying
258        $remove_dst = $matches[0][14]; // Dont delete files in destination
259
260        $data = array(OG_REST_PARAM_CLIENTS => $ips,
261                OG_REST_PARAM_DISK => $disk,
262                OG_REST_PARAM_PART => $part,
263                OG_REST_PARAM_CODE => $code,
264                OG_REST_PARAM_ID => $image_id,
265                OG_REST_PARAM_NAME => $name,
266                OG_REST_PARAM_REPOS => $repos,
267                OG_REST_PARAM_SYNC_PARAMS => array(
268                        OG_REST_PARAM_SYNC => $sync,
269                        OG_REST_PARAM_DIFF => $diff,
270                        OG_REST_PARAM_REMOVE => $remove,
271                        OG_REST_PARAM_COMPRESS => $compress,
272                        OG_REST_PARAM_CLEANUP => $cleanup,
273                        OG_REST_PARAM_CACHE => $cache,
274                        OG_REST_PARAM_CLEANUP_CACHE => $cleanup_cache,
275                        OG_REST_PARAM_REMOVE_DST => $remove_dst,
276                )
277        );
278
279        common_request(OG_REST_CMD_CREATE_BASIC_IMAGE, POST, $data);
280}
281
282function create_incremental_image($string_ips, $params) {
283
284        preg_match_all('/(?<=\=)[^\r]*(?=\r)?/', $params, $matches);
285
286        $ips = explode(';',$string_ips);
287        $disk = $matches[0][0];
288        $part = $matches[0][1];
289        $id = $matches[0][2];
290        $name = $matches[0][3];
291        $repos = $matches[0][4];
292        $diff_id = $matches[0][5];
293        $diff_name = $matches[0][6];
294        $path = $matches[0][7];
295        $sync = $matches[0][8];
296        $diff = $matches[0][9];
297        $remove = $matches[0][10];
298        $compress = $matches[0][11];
299        $cleanup = $matches[0][12];
300        $cache = $matches[0][13];
301        $cleanup_cache = $matches[0][14];
302        $remove_dst = $matches[0][15];
303
304        $data = array(OG_REST_PARAM_CLIENTS => $ips,
305                OG_REST_PARAM_DISK => $disk,
306                OG_REST_PARAM_PART => $part,
307                OG_REST_PARAM_ID => $id,
308                OG_REST_PARAM_NAME => $name,
309                OG_REST_PARAM_REPOS => $repos,
310                OG_REST_PARAM_SYNC_PARAMS => array(
311                        OG_REST_PARAM_SYNC => $sync,
312                        OG_REST_PARAM_PATH => $path,
313                        OG_REST_PARAM_DIFF => $diff,
314                        OG_REST_PARAM_DIFF_ID => $diff_id,
315                        OG_REST_PARAM_DIFF_NAME => $diff_name,
316                        OG_REST_PARAM_REMOVE => $remove,
317                        OG_REST_PARAM_COMPRESS => $compress,
318                        OG_REST_PARAM_CLEANUP => $cleanup,
319                        OG_REST_PARAM_CACHE => $cache,
320                        OG_REST_PARAM_CLEANUP_CACHE => $cleanup_cache,
321                        OG_REST_PARAM_REMOVE_DST => $remove_dst)
322        );
323
324        common_request(OG_REST_CMD_CREATE_INCREMENTAL_IMAGE, POST, $data);
325}
326
327function restore_basic_image($string_ips, $params) {
328
329        preg_match_all('/(?<=\=)[^\r]*(?=\r)?/', $params, $matches);
330
331        $ips = explode(';',$string_ips);
332        $disk = $matches[0][0];
333        $part = $matches[0][1];
334        $image_id = $matches[0][2];
335        $name = $matches[0][3];
336        $repos = $matches[0][4];
337        $profile = $matches[0][5];
338
339        $path = $matches[0][6];
340        $method = $matches[0][7];
341        $sync = $matches[0][8]; // Syncronization method
342
343        $type = $matches[0][9];
344
345        $diff = $matches[0][10]; // Send the whole file if there are differences
346        $remove = $matches[0][11]; // Delete files at destination that are not at source
347        $compress = $matches[0][12]; // Compress before sending
348
349        $cleanup = $matches[0][13]; // Delete image before creating it
350        $cache = $matches[0][14]; // Copy image to cache
351        $cleanup_cache = $matches[0][15]; // Delete image from cache before copying
352        $remove_dst = $matches[0][16]; // Dont delete files in destination
353
354        $data = array(OG_REST_PARAM_CLIENTS => $ips,
355                OG_REST_PARAM_DISK => $disk,
356                OG_REST_PARAM_PART => $part,
357                OG_REST_PARAM_ID => $image_id,
358                OG_REST_PARAM_NAME => $name,
359                OG_REST_PARAM_REPOS => $repos,
360                OG_REST_PARAM_PROFILE => $profile,
361                OG_REST_PARAM_TYPE => $type,
362                OG_REST_PARAM_SYNC_PARAMS => array(
363                        OG_REST_PARAM_PATH => $path,
364                        OG_REST_PARAM_METHOD => $method,
365                        OG_REST_PARAM_SYNC => $sync,
366                        OG_REST_PARAM_DIFF => $diff,
367                        OG_REST_PARAM_REMOVE => $remove,
368                        OG_REST_PARAM_COMPRESS => $compress,
369                        OG_REST_PARAM_CLEANUP => $cleanup,
370                        OG_REST_PARAM_CACHE => $cache,
371                        OG_REST_PARAM_CLEANUP_CACHE => $cleanup_cache,
372                        OG_REST_PARAM_REMOVE_DST => $remove_dst,
373                )
374        );
375
376        common_request(OG_REST_CMD_RESTORE_BASIC_IMAGE, POST, $data);
377}
378
379function restore_incremental_image($string_ips, $params) {
380
381        preg_match_all('/(?<=\=)[^\r]*(?=\r)?/', $params, $matches);
382
383        $ips = explode(';',$string_ips);
384        $disk = $matches[0][0];
385        $part = $matches[0][1];
386        $image_id = $matches[0][2];
387        $name = $matches[0][3];
388        $repos = $matches[0][4];
389        $profile = $matches[0][5];
390        $diff_id = $matches[0][6];
391        $diff_name = $matches[0][7];
392        $path = $matches[0][8];
393        $method = $matches[0][9];
394        $sync = $matches[0][10];
395        $type = $matches[0][11];
396        $diff = $matches[0][12];
397        $remove = $matches[0][13];
398        $compress = $matches[0][14];
399        $cleanup = $matches[0][15];
400        $cache = $matches[0][16];
401        $cleanup_cache = $matches[0][17];
402        $remove_dst = $matches[0][18];
403
404        $data = array(OG_REST_PARAM_CLIENTS => $ips,
405                OG_REST_PARAM_DISK => $disk,
406                OG_REST_PARAM_PART => $part,
407                OG_REST_PARAM_ID => $image_id,
408                OG_REST_PARAM_NAME => $name,
409                OG_REST_PARAM_REPOS => $repos,
410                OG_REST_PARAM_PROFILE => $profile,
411                OG_REST_PARAM_TYPE => $type,
412                OG_REST_PARAM_SYNC_PARAMS => array(
413                        OG_REST_PARAM_DIFF_ID => $diff_id,
414                        OG_REST_PARAM_DIFF_NAME => $diff_name,
415                        OG_REST_PARAM_PATH => $path,
416                        OG_REST_PARAM_METHOD => $method,
417                        OG_REST_PARAM_SYNC => $sync,
418                        OG_REST_PARAM_DIFF => $diff,
419                        OG_REST_PARAM_REMOVE => $remove,
420                        OG_REST_PARAM_COMPRESS => $compress,
421                        OG_REST_PARAM_CLEANUP => $cleanup,
422                        OG_REST_PARAM_CACHE => $cache,
423                        OG_REST_PARAM_CLEANUP_CACHE => $cleanup_cache,
424                        OG_REST_PARAM_REMOVE_DST => $remove_dst,
425                )
426        );
427
428        common_request(OG_REST_CMD_RESTORE_INCREMENTAL_IMAGE, POST, $data);
429}
430
431function poweroff($string_ips) {
432
433        $ips = explode(';',$string_ips);
434
435        $data = array(OG_REST_PARAM_CLIENTS => $ips);
436
437        common_request(OG_REST_CMD_POWEROFF, POST, $data);
438}
439
440function reboot($string_ips) {
441
442        $ips = explode(';',$string_ips);
443
444        $data = array(OG_REST_PARAM_CLIENTS => $ips);
445
446        common_request(OG_REST_CMD_REBOOT, POST, $data);
447}
448
449function stop($string_ips) {
450
451        $ips = explode(';',$string_ips);
452
453        $data = array(OG_REST_PARAM_CLIENTS => $ips);
454
455        common_request(OG_REST_CMD_STOP, POST, $data);
456}
457
458function refresh($string_ips) {
459
460        $ips = explode(';',$string_ips);
461
462        $data = array(OG_REST_PARAM_CLIENTS => $ips);
463
464        common_request(OG_REST_CMD_REFRESH, POST, $data);
465}
466
467function hardware($string_ips) {
468
469        $ips = explode(';',$string_ips);
470
471        $data = array(OG_REST_PARAM_CLIENTS => $ips);
472
473        common_request(OG_REST_CMD_HARDWARE, POST, $data);
474}
475
476function software($string_ips, $params) {
477
478        preg_match_all('/(?<=\=)(.*?)(?=\r)/', $params, $matches);
479
480        $ips = explode(';',$string_ips);
481        $disk = $matches[0][0];
482        $part = $matches[0][1];
483
484        $data = array(OG_REST_PARAM_CLIENTS => $ips,
485                OG_REST_PARAM_DISK => $disk,
486                OG_REST_PARAM_PART => $part);
487
488        common_request(OG_REST_CMD_SOFTWARE, POST, $data);
489}
490
491function setup($string_ips, $params) {
492
493        preg_match_all('/(?<=\=)(?!dis)(.*?)((?=\*)|(?=\r)|(?=\!)|(?=\%))/',
494                $params, $matches);
495
496        $ips = explode(';',$string_ips);
497        $disk = $matches[0][0];
498        $cache = $matches[0][2];
499        $cache_size = $matches[0][3];
500        $partition_number = array();
501        $partition_code = array();
502        $file_system = array();
503        $part_size = array();
504        $format = array();
505        for ($x = 0; $x < 4; $x++) {
506                $partition_number[$x] = $matches[0][4 + 5 * $x];
507                $partition_code[$x] = $matches[0][5 + 5 * $x];
508                $file_system[$x] = $matches[0][6 + 5 * $x];
509                $part_size[$x] = $matches[0][7 + 5 * $x];
510                $format[$x] = $matches[0][8 + 5 * $x];
511        }
512
513        $data = array(
514                OG_REST_PARAM_CLIENTS => $ips,
515                OG_REST_PARAM_DISK => $disk,
516                OG_REST_PARAM_CACHE => $cache,
517                OG_REST_PARAM_CACHE_SIZE => $cache_size,
518                OG_REST_PARAM_PARTITION_SETUP => array()
519        );
520
521        for ($i = 0; $i < sizeof($partition_number); $i++) {
522                $partition_setup = array(
523                        OG_REST_PARAM_PART => $partition_number[$i],
524                        OG_REST_PARAM_CODE => $partition_code[$i],
525                        OG_REST_PARAM_FILE_SYSTEM => $file_system[$i],
526                        OG_REST_PARAM_SIZE => $part_size[$i],
527                        OG_REST_PARAM_FORMAT => $format[$i]
528                );
529                array_push($data[OG_REST_PARAM_PARTITION_SETUP], $partition_setup);
530        }
531
532        common_request(OG_REST_CMD_SETUP, POST, $data);
533}
534
535function run_schedule($string_ips) {
536        $ips = explode(';',$string_ips);
537        $data = array(OG_REST_PARAM_CLIENTS => $ips);
538        common_request(OG_REST_CMD_RUN_SCHEDULE, POST, $data);
539}
540
541/*
542 * @function multiRequest.
543 * @param    URLs array (may include header and POST data), cURL options array.
544 * @return   Array of arrays with JSON requests and response codes.
545 * @warning  Default options: does not verifying certificate, connection timeout 200 ms.
546 * @Date     2015-10-14
547 */
548function multiRequest($data, $options=array(CURLOPT_SSL_VERIFYHOST => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_TIMEOUT_MS => 500)) {
549 
550  // array of curl handles
551  $curly = array();
552  // Data to be returned (response data and code)
553  $result = array();
554 
555  // multi handle
556  $mh = curl_multi_init();
557 
558  // loop through $data and create curl handles
559  // then add them to the multi-handle
560  foreach ($data as $id => $d) {
561 
562
563    $curly[$id] = curl_init();
564 
565    $url = (is_array($d) && !empty($d['url'])) ? $d['url'] : $d;
566    curl_setopt($curly[$id], CURLOPT_URL, $url);
567    // HTTP headers?
568    if (is_array($d) && !empty($d['header'])) {
569       curl_setopt($curly[$id], CURLOPT_HTTPHEADER, $d['header']);
570    } else {
571       curl_setopt($curly[$id], CURLOPT_HEADER, 0);
572    }
573    curl_setopt($curly[$id], CURLOPT_RETURNTRANSFER, 1);
574 
575    // post?
576    if (is_array($d)) {
577      if (!empty($d['post'])) {
578        curl_setopt($curly[$id], CURLOPT_POST, 1);
579        curl_setopt($curly[$id], CURLOPT_POSTFIELDS, $d['post']);
580      }
581    }
582
583    // extra options?
584    if (!empty($options)) {
585      curl_setopt_array($curly[$id], $options);
586    }
587 
588    curl_multi_add_handle($mh, $curly[$id]);
589  }
590 
591  // execute the handles
592  $running = null;
593  do {
594    curl_multi_exec($mh, $running);
595  } while($running > 0);
596 
597 
598  // Get content and HTTP code, and remove handles
599  foreach($curly as $id => $c) {
600    $result[$id]['data'] = curl_multi_getcontent($c);
601    $result[$id]['code'] = curl_getinfo($c, CURLINFO_HTTP_CODE);
602    curl_multi_remove_handle($mh, $c);
603  }
604
605 // all done
606  curl_multi_close($mh);
607 
608  return $result;
609}
610
Note: See TracBrowser for help on using the repository browser.