[asterisk-users] AGI Help Please
yusuf
yusuf at ecntelecoms.com
Tue Dec 19 00:35:56 MST 2006
William Piper wrote:
> 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
>
Hi,
to see debug output for AGI's, you *must* be connected to the first Ast terminal. So start Asterisk
like 'asterisk -cvvvvvvvvvvvvvv', then you will see output from your AGI.
--
thanks,
yusuf
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
More information about the asterisk-users
mailing list