GET_status('current', $id), true)['value']['data']; $status_before = (object) $status_before; if (mappingstatus($status_before->status) != $action) { if(in_array($action, ["shutdown","stop","reset"]) && $status_before->status == "stopped") { echo "Action not available! VM ".$status_before->name." is currently :".$status_before->status.""; } else if ($action == "current") { echo "The VM ".$status_before->name." is currently ".$status_before->status.""; } else { $status_after = $status_before; $q->GET_status($action, $id); for ($i = 1; ($status_after->status == $status_before->status) && $i <= 9; $i++) { sleep(3); // 30s max (10*3) $status_after = json_decode($q->GET_status('current', $id), true)['value']['data']; $status_after = (object) $status_after; } if($status_after->status == $status_before->status) { echo "Command time out"; } else { echo "The VM ".$status_after->name." is now :".$status_after->status.""; } } } else { echo "Your VM ".$status_before->name." is already:".$status_before->status.""; }