source: admin/WebConsole/includes/restfunctions.php @ 8b9b6ec

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 8b9b6ec was 436abc7, checked in by Ramón M. Gómez <ramongomez@…>, 6 years ago

#915 Change WebConsole? to read API token from ogAdmServer.cfg

This commit changes restfunctions.php to read the API token of
ogAmdServer from ogAdmRepo.cfg to ogAdmServer.cfg. This way it avoids
possible communication errors if ogAdmRepo.cfg and ogAdmServer.cfg are
desynced.

In order to restfuntions.php can read ogAdmServer.cfg this commit
also changes the permissions of the file.

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