twitter feed0xdecafbad.com

Better XML-CDR processing for FreeSWITCH

by 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.


3 Comments for this entry

  • Shery

    Keep working ,great job!

  • Diego

    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?

  • trixter

    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.

Leave a Reply

ERROR: si-captcha.php plugin says GD image support not detected in PHP!

Contact your web host and ask them why GD image support is not enabled for PHP.

ERROR: si-captcha.php plugin says imagepng function not detected in PHP!

Contact your web host and ask them why imagepng function is not enabled for PHP.

ERROR: si-captcha.php plugin says GD image support not detected in PHP!

Contact your web host and ask them why GD image support is not enabled for PHP.

ERROR: si-captcha.php plugin says imagepng function not detected in PHP!

Contact your web host and ask them why imagepng function is not enabled for PHP.

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!