File: examples.html.in

package info (click to toggle)
libvirt-php 0.5.2~30-g64dca6f-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,460 kB
  • ctags: 5,538
  • sloc: cpp: 11,159; ansic: 8,250; xml: 3,999; php: 1,604; sh: 580; makefile: 189; perl: 97
file content (72 lines) | stat: -rw-r--r-- 2,612 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<html>
  <body>
    <h1>Examples</h1>

    <ul id="toc"></ul>

    <h2><a name="get-version">Getting libvirt, hypervisor and libvirt-php version</a></h2>

     <p>If you just want to check whether the module is working fine you can try to ask libvirt for
     libvirt/hypervisor version and libvirt-php version. Libvirt-php version is also available in
     phpinfo() output when a module is loaded. In your PHP script you can do it using following
     syntax:</p>
     <pre>&lt;&#63;php
     print_r ( libvirt_version() );
&#63;&gt;</pre>

      <p>The output will be having information about major, minor and release versions of the hypervisor
      (if connected and applicable) and libvirt available and also there will be version number of libvirt-php
      connector in form of <i>major.minor.release</i>.</p>

     <h2><a name="connecting">Connecting to libvirt daemon with debugging</a></h2>

     <p>
       For connecting to libvirt daemon the <i>libvirt_connect()</i> API function has been introduced.
       This function accepts 2 arguments:</p>

      <ul>
        <li>Hypevisor URI: string</li>
        <li>Readonly: boolean</li>
      </ul>

     <p>Hypervisor URI could be also string <i>null</i> to make libvirt probe the hypervisor driver
        that is applicable to the host machine.</p>
     <p>To turn on the debugging you need to call <i>libvirt_logfile_set()</i> API function to tell
        libvirt-php to enable logging to file. Logging is disabled by default.</p>

     <pre>&lt;&#63;php
    $logfile = 'test.log';

    unlink($logfile);
    if (!libvirt_logfile_set($logfile))
         die('Cannot set the log file');

    $conn = libvirt_connect('null', false);
    unset($conn);

    $fp = fopen($logfile, 'r');
    $str = fread($fp, filesize($logfile));
    fclose($fp);

    echo $str;
&#63;&gt;</pre>

    <p>This will print the connection result as logged into the <i>test.log</i> file.</p>

     <h2><a name="listing-domains">Getting list of domains</a></h2>

     <p>
       If you want to get the list of domains you can use <i>libvirt_list_domains()</i> API function.
       This function returns an array of libvirt domain resources that could be used with the
       <i>libvirt_domain_get_name()</i> API function to get the list of domain names like:</p>

     <pre>&lt;&#63;php
     $conn = libvirt_connect('null', false);
     $doms = libvirt_list_domains($conn);
     print_r($doms);
&#63;&gt;</pre>

     <p>This script will output all the domain names available on this connection (all of them are temporarily stored in <i>$doms</i> array).</p>

  </body>
</html>