source: admin/WebConsole/includes/restfunctions.php @ 227093f

918-git-images-111dconfigure-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 227093f was 9381fdf, checked in by OpenGnSys Support Team <soporte-og@…>, 5 years ago

#915 Rename POST /image/setup for /setup in REST API

This patch renames the setup command to avoid semantic confusion.

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