XML Statistics for individual SMSC Connection

XML Statistics for individual SMSC Connection SearchSearch
Author Message
Des - NowSMS Support
Board Administrator
Username: Desosms

Post Number: 5428
Registered: 08-2008
Posted on Thursday, August 27, 2015 - 03:48 pm:   

From the support mailbox...


quote:

Hi

When I am trying to query the number of messages for Today using below code, I am getting results from ALL SMSC connections. How can I get the number of ONLY one SMSC connection? Snippet of my XML is below for your reference.

$valu=$xml.NowSMSStatus.SMSCStatus.MessagesToday




This question references the PHP example at http://www.nowsms.com/nowsms-status-query-with-php

And the XML status query interface described at http://www.nowsms.com/xml-status-query-for-smsc-connection-status-and-statistics

The PHP example loads the current status via HTTP into a simple XML element with the following two lines of code:

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


Once loaded, various statistics can be easily extracted from the XML. For example, to retrieve the number of SMS messages sent today, the following syntax can be used:

$xml->SMSSent->MessagesToday


Statistics are also available for each SMSC and MMS connection.

In the XML, each SMSC connection has a separate <SMSCStatus> element, like this:

<SMSCStatus> 
<Name>SMPP – xps5:9000</Name>
<Status>OK</Status>
<MessagesToday>44640</MessagesToday>
<MessagesLast7Days>44640</MessagesLast7Days>
<MessagesLast30Days>44640</MessagesLast30Days>
</SMSCStatus>
<SMSCStatus>
<Name>SMPP – xps5:9001</Name>
<Status>OK</Status>
<MessagesToday>43369</MessagesToday>
<MessagesLast7Days>43369</MessagesLast7Days>
<MessagesLast30Days>43369</MessagesLast30Days>
</SMSCStatus>


To retrieve the statistics for an individual connection, it is necessary to iterate through the XML using the foreach directive.

The following is a simple example that outputs total messages sent today, then outputs the number of messages sent by each connection:

echo "SMS Sent Today = " . $xml->SMSSent->MessagesToday . "<br/>\r\n"; 

// For each <SMSCStatus> node, we echo the name and sent messages count.
foreach ($xml->SMSCStatus as $SMSCStatus) {
echo "For " . $SMSCStatus->Name . ", SMS Sent Today = " . $SMSCStatus->MessagesToday . "<br/>\r\n";
}




--
Des
NowSMS Support