IP Asterisk . , . , , . PHP , (.wav) . , .


PHP 23 . - days. , :

<?php
$days = 180; //,   180   .      ;
$hostname = "localhost"; //      ,   IP -  Asterisk,    localhost.     IP - ;
$username = "delete"; //      asteriskcdrdb
$password = "333jIje45"; //      asteriskcdrdb
$dbName = "asteriskcdrdb";
$file = '/home/admin/log_mail.txt';
$cdate =  date('Y-m-d H:i:s', strtotime('-'.$days.' days')); //   .     ,  ;
$adate = date('Y-m-d H:i:s'); //       ;
/*   */ 
mysql_connect($hostname,$username,$password) OR DIE("    "); 
mysql_select_db($dbName) or die(mysql_error());
/*       cdr*/ 
$query = "DELETE from cdr WHERE calldate < '$cdate';";
$res=mysql_query($query) or die(mysql_error());
/*     */ 
$number = mysql_affected_rows(); 
/*    -   */
echo exec('find /var/spool/asterisk/monitor/ -type f -mtime +'.$days.' -exec rm -rf {} \;');
$current = "DELETE :: $adate :: $number records were deleted from CDR\n";
file_put_contents($file, $current, FILE_APPEND | LOCK_EX); //    ;
?>
    Asterisk

.php.


, , , . , :

[root@asterisk]# mysql
mysql>CREATE USER 'delete'@'localhost' IDENTIFIED BY '333jIje45';

:

mysql> GRANT DELETE, SELECT ON asteriskcdrdb.cdr TO 'delete';

. cron . crontab -e :

*/2 10-18 * * 1-5 /usr/bin/php /home/deletecdr.php

, 2 , 10:00 18:00. , /home/deletecdr.php - . :)


?

 .

P.S. , :)

"",