source: admin/WebConsole/includes/restfunctions.php @ 15243d4

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 15243d4 was 15243d4, checked in by OpenGnSys Support Team <soporte-og@…>, 6 years ago

#915 Fix run script command

This patch fixes run script command as it now uses REST API instead of
SocketHidra?.

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