diff --git a/app/xml_cdr/resources/service/xml_cdr.php b/app/xml_cdr/resources/service/xml_cdr.php new file mode 100644 index 0000000000..19f5450a50 --- /dev/null +++ b/app/xml_cdr/resources/service/xml_cdr.php @@ -0,0 +1,188 @@ +get('xml_cdr', '$interval'); + +//make sure the /var/run/fusionpbx directory exists + if (!file_exists('/var/run/fusionpbx')) { + $result = mkdir('/var/run/fusionpbx', 0777, true); + if (!$result) { + die('Failed to create /var/run/fusionpbx'); + } + } + +//create the process id file if the process doesn't exist + if (!$pid_exists) { + //remove the old pid file + if (file_exists($pid_file)) { + unlink($pid_file); + } + + //show the details to the user + if (isset($debug) && $debug == true) { + echo "\n"; + echo "Service: ".basename( $argv[0], ".php")."\n"; + echo "Process ID: ".getmypid()."\n"; + echo "PID File: ".$pid_file."\n"; + } + + //save the pid file + file_put_contents($pid_file, getmypid()); + } + + + +//import the call detail records from HTTP POST or file system + $cdr = new xml_cdr; + +//get the cdr record + $xml_cdr_dir = $setting->get('switch', 'log').'/xml_cdr'; + +//loop through + while (true) { + + //import the call detail records from HTTP POST or file system + if (!$cdr) { + $cdr = new xml_cdr; + } + + //find and process cdr records + $xml_cdr_array = glob($xml_cdr_dir.'/*.cdr.xml'); + if (!empty($xml_cdr_array)) { + $i = 0; + foreach ($xml_cdr_array as $xml_cdr_file) { + //add debug information + if (isset($debug) && $debug == true) { + echo $xml_cdr_file."\n"; + } + + //get the content from the file + $call_details = file_get_contents($xml_cdr_file); + + //process the call detail record + if (isset($xml_cdr_file) && isset($call_details)) { + //set the file + $cdr->file = basename($xml_cdr_file); + + //get the leg of the call and the file prefix + if (substr(basename($xml_cdr_file), 0, 2) == "a_") { + $leg = "a"; + } + else { + $leg = "b"; + } + + //decode the xml string + if (substr($call_details, 0, 1) == '%') { + $call_details = urldecode($call_details); + } + + //parse the xml and insert the data into the db + $cdr->xml_array($i, $leg, $call_details); + } + $i++; + } + } + + //sleep for a moment + usleep(100000); + + //debug info + if (!empty($debug) && $debug_level == '2') { + //current memory + $memory_usage = memory_get_usage(); + + //peak memory + $memory_peak = memory_get_peak_usage(); + echo "\n"; + echo 'Current memory: ' . round($memory_usage / 1024) . " KB\n"; + echo 'Peak memory: ' . round($memory_peak / 1024) . " KB\n\n"; + echo "\n"; + } + + } + +?>