[libvirt] [libvirt-php][PATCH 1/3] examples: Check properly if connected
Michal Privoznik
mprivozn at redhat.com
Tue Apr 19 13:46:40 UTC 2016
So far, we connect and issue an API immediately. And only after
it fails we assume we're not connected. This is just not right
as we should have checked before issuing the API whether we are
connected at all.
Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
---
examples/index.php | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/examples/index.php b/examples/index.php
index 381baef..b2f5b69 100644
--- a/examples/index.php
+++ b/examples/index.php
@@ -1,9 +1,11 @@
<?php
require('libvirt.php');
$lv = new Libvirt('qemu:///system');
+ if ($lv == false)
+ die('<html><body>Cannot open connection to hypervisor</body></html>');
$hn = $lv->get_hostname();
if ($hn == false)
- die('Cannot open connection to hypervisor</body></html>');
+ die('<html><body>Cannot get hostname</body></html>');
$action = array_key_exists('action', $_GET) ? $_GET['action'] : false;
$subaction = array_key_exists('subaction', $_GET) ? $_GET['subaction'] : false;
--
2.7.3
More information about the libvir-list
mailing list