# xAPI getstatus- PHP

**URL:** <https://community.a10networks.com/t/xapi-getstatus-php/48>\
**Category:** System\
**Created:** [May 11, 2011, 10:38pm UTC](https://community.a10networks.com/t/xapi-getstatus-php/48 "2011-05-11T22:38:49Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![JackofallTrades](https://avatars.discourse-cdn.com/v4/letter/j/a8b319/32.png) [@JackofallTrades](https://community.a10networks.com/u/JackofallTrades)\
**Post date:** [May 11, 2011, 10:38pm UTC](https://community.a10networks.com/t/xapi-getstatus-php/48/1 "2011-05-11T22:38:49Z")

</div>

**Posted by JackofallTrades** Below is a sample of code for accessing the xAPI via PHP. I am using xPath and pear HTTP/REQUEST2. I am not a coder so ignore my slop. First I define the login information and the xAPI path. The code snippet is ax\_main.php **Code:** `<?php //pear install HTTP_Request2 require 'HTTP/Request2.php'; //define username,password and host $username = 'admin'; $password = 'a10'; $host="172.21.21.50"; //define the xAPI define("AX_REST", "http://".$host."/services/rest/V1/"); ?> `From there I have a ax\_session\_id.php. This is where we grab the session\_id we will be using for the rest of the session. **Code:** `<?php $sid = 1; function getSid() { require 'ax_main.php'; $args = array( 'method' => 'authenticate', 'username' => $username, 'password' => $password); //http_build_query is only used here because I ran into a bug. $url = AX_REST . "?" . http_build_query($args); $Req = new HTTP_Request2(); $Req->setUrl($url); $res = $Req->send(); $sid_xml= $res->getBody(); //echo $sid_xml; $sid_local_scope = new SimpleXMLElement($sid_xml); $sid = $sid_local_scope->xpath('//session_id'); //I am using globals because I am lazy. $GLOBALS['sid'] = $sid[0]; } getSid(); //echo $GLOBALS['sid']; ?> `Here is the bit of code to get the status of the vips **Code:** `<?php //require_once 'ax_main.php'; $vip = ''; function getVip_status() { include 'ax_session_id.php'; //getSid(); //I ran into a bug so I am not using http_build_query $url = AX_REST . "?session_id=" .$GLOBALS['sid']."&method=slb.vip.getALL" ; //echo $url; $Req = new HTTP_Request2(); $Req->setUrl($url); $res = $Req->send(); $vip_xml= $res->getBody(); //echo $vip_xml; $vip_local_scope = new SimpleXMLElement($vip_xml); $virtual = $vip_local_scope->xpath('//virtual-server'); foreach ($virtual as $list) { if ($list->attributes()->status == 0) { $vip_status = "<font color=\"black\">disabled</font>"; } elseif ($list->attributes()->status == 1) { $vip_status = "<font color=\"green\">All Up</font>"; } elseif ($list->attributes()->status == 2) { $vip_status = "<font color=\"yellow\">Part Up</font>"; } elseif ($list->attributes()->status == 3) { $vip_status = "<font color=\"orange\">Func Up</font>"; } elseif ($list->attributes()->status == 4) { $vip_status = "<font color=\"red\">Down</font>"; } else { $vip_status = "<font color=\"blue\">Unknown</font>"; } echo "VIP: ".$list->attributes()->name." Status: ". $vip_status."<br>"; } } getVip_status(); ?> `Here is the code to get server status. **Code:** `<?php //get session ID $server = ''; function getServer_status() { include 'ax_session_id.php'; //getSid(); $url = AX_REST . "?" . "session_id=" .$GLOBALS['sid']."&method=slb.server.getALL"; $Req = new HTTP_Request2(); $Req->setUrl($url); $res = $Req->send(); $server_xml= $res->getBody(); //echo "server_xml = ".$server_xml."<br>"; $server_local_scope = new SimpleXMLElement($server_xml); $server_list = $server_local_scope->xpath('//server'); foreach ($server_list as $list) { if ($list->attributes()->status == 0) { $server_status = "<font color=\"black\">disabled</font>"; } elseif ($list->attributes()->status == 1) { $server_status = "<font color=\"green\">Up</font>"; } elseif ($list->attributes()->status == 4) { $server_status = "<font color=\"red\">Down</font>"; } else { $server_status = "<font color=\"blue\">Unknown</font>"; } echo "Server Name: ".$list->attributes()->name." Status is: ". $server_status."<br>"; } } getServer_status(); ?> `Enjoy!
