[asterisk-users] AGI Help Please

William Piper william.piper at gmail.com
Tue Dec 19 21:48:04 MST 2006


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/c69b2638/attachment.htm


More information about the asterisk-users mailing list