Examples

Getting libvirt, hypervisor and libvirt-php version

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:

<?php
     $conn = libvirt_version();
?>

The var variable will be having information about major, minor and release versions of the hypervisor and libvirt available and also there will be version number of libvirt-php connector in form of major.minor.release.

Connecting to libvirt daemon

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

Hypervisor URI could be also string null to make libvirt probe the hypervisor driver that is applicable to the host machine.

<?php
     $conn = libvirt_connect('null', false);
?>

Getting list of domains

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

<?php
     $conn = libvirt_connect('null', false);
     $doms = libvirt_list_domains($conn);
     $domNames = array();
     foreach ($doms as $dom)
         $domNames[] = libvirt_domain_get_name($dom);
     print_r($domNames);
?>

This script will output all the domain names available on this connection (all of them are temporarily stored in $domNames array).