[asterisk-users] AGI Help Please

William Piper william.piper at gmail.com
Tue Dec 19 22:11:44 MST 2006


Ok, further testing shows that the AGI is apparently running however the
information is still not displaying on the CLI.

Below are a few errors in the script and on a google search, although I
found people with the same error, I didn't find a resolution.

Any thoughts on what is causing this error?
Any thoughts as to why the output is not showing on the CLI without doing a
debug?

Thanks

    -- Executing AGI("SIP/216-e866", "test.php") in new stack
    -- Launched AGI Script /var/lib/asterisk/agi-bin/test.php
AGI Tx >> agi_request: test.php
AGI Tx >> agi_channel: SIP/216-e866
AGI Tx >> agi_language: en
AGI Tx >> agi_type: SIP
AGI Tx >> agi_uniqueid: 1166590405.17780
AGI Tx >> agi_callerid: 216
AGI Tx >> agi_calleridname: Billy Test
AGI Tx >> agi_callingpres: 0
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 0
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: 255
AGI Tx >> agi_rdnis: unknown
AGI Tx >> agi_context: admin
AGI Tx >> agi_extension: 255
AGI Tx >> agi_priority: 1
AGI Tx >> agi_enhanced: 0.0
AGI Tx >> agi_accountcode: test216
AGI Tx >> >
AGI Rx << >
AGI Tx >> 510 Invalid or unknown command
AGI Rx << >
AGI Tx >> 510 Invalid or unknown command
AGI Rx << VERBOSE"There have been"
AGI Tx >> 510 Invalid or unknown command
AGI Rx << VERBOSE"125 calls made"
AGI Tx >> 510 Invalid or unknown command
    -- AGI Script test.php completed, returning 0
    -- Executing Hangup("SIP/216-e866", "") in new stack



On 12/19/06, William Piper <william.piper at gmail.com> wrote:
>
> Jay,
>
> I just tried the suggested changes... same response.
> I tested the script via command-line & it works fine.
>
> [root at redhat agi-bin]# php test.php
> Content-type: text/html
> X-Powered-By: PHP/4.3.9
>
> VERBOSE"There have been"
> VERBOSE"1 calls made"
> [root at redhat agi-bin]#
>
> The permissions are correct:
> -rwxr-xr-x  1 root root  1004 Dec 19 23:42 test.php
>
> Any other thoughts?
> Thanks,
>
> bp
>
> On 12/19/06, Jay Milk <ast-users at skimmilk.net > wrote:
>
> > Does the script run from command-line?  Without taking a close look at
> > this, the include statements in the function body of connect_db look
> > potentially messy.
> >
> > Also, any output to stdout is interpreted by asterisk as a command, so
> > those fputs statements would be a problem -- do
> > fputs($stdout,"VERBOSE \"There have been\"\n");
> > fputs($stdout,"VERBOSE \"$row_count calls made\"\n");
> >
> > instead.
> >
> > 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,
> > >
> > _______________________________________________
> > --Bandwidth and Colocation provided by Easynews.com
> > <http://easynews.com/>--
> >
> > asterisk-users mailing list
> > To UNSUBSCRIBE or update options visit:
> >    http://lists.digium.com/mailman/listinfo/asterisk-users
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20061219/785700e2/attachment.htm


More information about the asterisk-users mailing list