Better XML-CDR processing for FreeSWITCH
by trixter on Apr.18, 2009, under Telephony
As some of you may know I wrote a xml-cdr curl processing class in PHP for FreeSWITCH. This was required because PHP4 did not have a native XML processor. PHP5 is old enough that it should be installed everywhere now, and that usually provides a simple xml parsing library. I like the simplexml stuff in PHP5 better than I do the stuff I wrote, so I will explain how to use it.
<?php
if(isset($_POST['cdr'])) {
$cdr = simplexml_load_string($_POST['cdr']);
// do your validation code here
// This is just an example, you would probably want to store this in a database instead
$fh = fopen(“/tmp/cdr.xml.”.uniqid(), ‘wb’);
fwrite($fh,”Channel created at ” . $cdr->callflow->times->created_time . “\n”);
fwrite($fh, $_POST['cdr'] . “\n\nprint_r\n\n”);
fwrite($fh,print_r($cdr,true).”\n\n”);
fclose($fh);}
?>
That is all there is to it, much easier to use, although there is a slightly different way to access variables from what I had previously written. You may notice the $cdr->callflow->times->created_time variable. How this works is you have an XML file, callflow is a child of the root node, times is a child of callflow and created_time is a child of times. It is fairly straight forward to process. If you have multiple entries for example application nodes in the app_log node, you would access it as $cdr->app_log->application[0] and so on.

May 6th, 2009 on 7:07 am
Keep working ,great job!
January 26th, 2010 on 7:18 am
Cool, but what are the advantages/disadvantages of getting the CDR vars from the CHANNEL_HANGUP_COMPLETE event and getting/parsing it from the XML CDR files?
February 4th, 2010 on 2:45 am
I do not know that there is any advantage to one vs the other. If you are processing the CDR records you will get the variables if they are from the XML CDR entry (not all CDR methods will have this ability). So it depends on what you are doing as to what the right tool for the job is.