Quantcast
Channel: NowSMS
Viewing all articles
Browse latest Browse all 92

NowSMS Status Query with PHP

$
0
0

Previous articles have described the XML-based status query interface that can be used to programmatically retrieve information about the current status of NowSMS. The XML-based status query interface that reports information similar to what is reported on the “Status” page of the NowSMS configuration dialog. The query results include information about SMSC connection status, the number of messages processed via the different connections, and the number of messages pending in the queues, among other information.

This interface is described in more detail in the following article:

http://www.nowsms.com/xml-status-query-for-smsc-connection-status-and-statistics

An XML Schema Definition can be found in the following article:

http://www.nowsms.com/xml-status-query-for-smsc-connection-status-and-statistics-2

As we frequently receive questions asking how this status information can be accessed via a PHP script, this article will provide some simple examples.

The PHP SimpleXML functions are the easiest way to access and process this information.

In a discussion board posting (http://www.nowsms.com/discus/messages/1/60149.html), we previously provided a simple example of a PHP script that queries the number of messages waiting in the NowSMS outbound SMS message queue.

The first step to access the data is to load the status URL into a SimpleXML object:

<?php

$xmldata = file_get_contents
             ("http://127.0.0.1:8800/admin/xmlstatus?user=adminuser&password=adminpass");
$xml = simplexml_load_string($xmldata);
?>

Substitute in your appropriate IP address and port, and the appropriate “adminuser” and “adminpass” values for your NowSMS installation.

To report the number of messages in the outbound SMS message queue, simply access the following variable:

$xml->SMSOUTQ

To report the number of messages sent out today, or in the last 7 or last 30 days, use the following variables:

$xml->SMSSent->MessagesToday
$xml->SMSSent->MessagesLast7Days
$xml->SMSSent->MessagesLast30Days

To report the number of active SMPP client connections, use the following variable:

$xml->SMPPClientList->ActiveConnectionCount

Refer to the XML examples and schema referenced in the earlier links to see other status information that is available via this XML-based interface.

As an additional example, here is code that queries SMSC connection status and reports any connections that are experiencing connectivity problems:

<?php

$xmldata = file_get_contents
            ("https://127.0.0.1:8801/admin/xmlstatus?user=adminuser&password=adminpass");
$xml = simplexml_load_string($xmldata);
$allConnectionsOK = true;
foreach ($xml->SMSCStatus as $smscStatus) {
   if (strcasecmp ($smscStatus->Status, "OK")) {
      $allConnectionsOK = false;
      echo "Connection Error: " . $smscStatus->Name . " -- " . $smscStatus->StatusDetail . "\n";
   }
}
if ($allConnectionsOK) {
   echo "OK\n";
}
?>

For more information on using the SimpleXML functions, please refer to the PHP documentation at:   http://us.php.net/manual/en/book.simplexml.php

For more information on the NowSMS Status Query XML interface, please refer to the following articles:

 


Viewing all articles
Browse latest Browse all 92

Trending Articles