This patch for libvirt-php Pre-4.2 version.
I checked with libvirt 0.8.8 version.

I fixed irConnectClose failed issue on list_domains.
And web example codes updated for 0.8.8 API.

This issue is:
$domains = libvirt_list_domains($conn);
PHP Warning: main(): virConnectClose failed with 1 on destructor: (null)

And if ssh connect to remote host then some netcat processes remain on remote host.

# ps axu|grep libvirt|grep 'nc -U'
apache 27867 0.0 0.0 7332 368 ? Ss 12:09 0:00 nc -U /var/run/libvirt/libvirt-sock
apache 27871 0.0 0.0 7332 372 ? Ss 12:09 0:00 nc -U /var/run/libvirt/libvirt-sock
apache 27875 0.0 0.0 7332 368 ? Ss 12:09 0:00 nc -U /var/run/libvirt/libvirt-sock

Thanks for libvirt-php.
Regards,
==
Yukihiro Kawada


diff --git a/examples/libvirt.php b/examples/libvirt.php
index 10e7e38..8a54acd 100644
--- a/examples/libvirt.php
+++ b/examples/libvirt.php
@@ -22,7 +22,7 @@
}

function get_hostname() {
- return libvirt_get_hostname($this->conn);
+ return libvirt_connect_get_hostname($this->conn);
}

function get_domain_object($nameRes) {
@@ -178,30 +178,23 @@
}

function get_uri() {
- return libvirt_get_uri($this->conn);
+ return libvirt_connect_get_uri($this->conn);
}

function get_domain_count() {
- $ac = libvirt_get_active_domain_count($this->conn);
- $ic = libvirt_get_inactive_domain_count($this->conn);
- $tc = libvirt_get_domain_count($this->conn);
-
- return array(
- 'active' => $ac,
- 'inactive' => $ic,
- 'total' => $tc
- );
+ return libvirt_domain_get_counts($this->conn);
}

function get_domains() {
$domNames = array();

$doms = libvirt_list_domains($this->conn);
- foreach ($doms as $dom) {
- $tmp = libvirt_domain_get_uuid_string($dom);
- $domNames[$tmp] = libvirt_domain_get_name($dom);
+ foreach ($doms as $nam) {
+ $dom = libvirt_domain_lookup_by_name($this->conn, $nam);
+ $tmp = libvirt_domain_get_uuid_string($dom);
+ $domNames[$tmp] = $nam;
}
-
+ unset($doms);
ksort($domNames);
return $domNames;
}
@@ -316,7 +309,7 @@
$ret = array();

if ($name != false) {
- $dom=libvirt_domain_lookup_by_name($this->conn, $name);
+ $dom = libvirt_domain_lookup_by_name($this->conn, $name);
if (!$dom)
return false;

diff --git a/src/libvirt-php.c b/src/libvirt-php.c
index 5e77994..f5a927b 100644
--- a/src/libvirt-php.c
+++ b/src/libvirt-php.c
@@ -3467,7 +3467,7 @@ PHP_FUNCTION(libvirt_list_domains)
int *ids;
char **names;
const char *name;
- int i;
+ int i, rv;
virDomainPtr domain=NULL;

GET_CONNECTION_FROM_ARGS("r",&zconn);
@@ -3490,6 +3490,12 @@ PHP_FUNCTION(libvirt_list_domains)
}
efree(ids);

+ rv = virDomainFree (domain); // Y.Kawada
+ if (rv != 0) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,"virDomainFree failed with %i on list_domain: %s", rv, LIBVIRT_G (last_error));
+ }
+ domain = NULL;
+
expectedcount=virConnectNumOfDefinedDomains (conn->conn);
names=emalloc(expectedcount*sizeof(char *));
count=virConnectListDefinedDomains (conn->conn,names ,expectedcount);