[asterisk-users] AGI Help Please
Jay Milk
ast-users at skimmilk.net
Wed Dec 20 07:42:51 MST 2006
Try running it as
./test.php
the hash-bang should take care of the php-location.
The first two lines are one cause of your problem. Could be the lack of
the "-q" param for php. However, I would expect the script to not show
anything, as it should be reading params from asterisk first. Iirc,
asterisk is picky about the order in which commands are accepted --
sending commands (such as VERBOSE) before pulling its output buffer,
could be problematic.
William Piper 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
> <mailto: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,
>
More information about the asterisk-users
mailing list