[asterisk-users] AGI Help Please

William Piper william.piper at gmail.com
Mon Dec 18 23:15:27 MST 2006


List,

I finally decided to break down & start playing with AGI scripts, but for
the life of me, I can't figure out what I am doing wrong.

Below is a super simple script to run a query in mysql to see how many call
records there are for the extension calling in, then print the total in the
CLI.

This is all I get on the CLI:
    -- Executing AGI("SIP/216-0baa", "test.php") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/test.php
    -- AGI Script test.php completed, returning 0
    -- Executing Hangup("SIP/216-0baa", "") in new stack


Here is the script:
#!/usr/bin/php -q
<?php
ob_implicit_flush(false);
set_time_limit(6);
$stdin  = fopen("php://stdin","r");
$stdout = fopen('php://stdout', 'w');

function read() {
  global $stdin, $debug;
  $input = str_replace("\n", "", fgets($stdin, 4096));
  return $input;
}
function connect_db() {
$database="asteriskcdrdb";
 include("./common.php");
 include("./dbconnect.php");
 }

// parse agi headers into array
while ($env=read()) {
  $env = str_replace("\"","",$env);
  $s = split(": ",$env);
  $agi[str_replace("agi_","",$s[0])] = trim($s[1]);
     if (($env == "") || ($env == "\n")) {
     break;
  }
}

// main program
$clid = $agi[callerid];
connect_db();

$query1 = "SELECT * FROM cdr WHERE dst = '$clid' ";
$query_result1 = @mysql_query($query1);
$row_count = mysql_num_rows($query_result1);
$row1 = @mysql_fetch_array ($query_result1);

fputs($stdout,"There have been\n");
fputs($stdout,"$row_count calls made\n");

fflush($stdout);
fclose($stdin);
fclose($stdout);
exit;
?>

There are no debug errors and the query is going through just fine... and
yes, I chmod 755.
Does anyone have a clue what I am doing wrong?

Thanks,

bp
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20061218/c0d93d76/attachment.htm


More information about the asterisk-users mailing list