Stop Asterisk.  Start Asterisk as "asterisk -cvvvd" then in the CLI issue the 
command "agi set debug on".

Starting Asterisk as this command will make it run in the foreground and show 
you STDERR.  You do not normally get to see STDERR when running AGIs in 
Asterisk.    Since Asterisk is running in the foreground, if you do a ctrl-S to 
stop output it pauses Asterisk's call processing.  Remember that.      

This should help you figure out what is wrong.    Personally, I use the PHPAGI 
library and don't worry about all the low level stuff.

-----Original Message-----
From: asterisk-users-boun...@lists.digium.com 
[mailto:asterisk-users-boun...@lists.digium.com] On Behalf Of Muhammad
Sent: Sunday, January 20, 2013 6:46 AM
To: Asterisk Users Mailing List - Non-Commercial Discussion
Subject: Re: [asterisk-users] AGI command

Thanks Salman.
Here is my cli debug when run agi:



    -- Launched AGI Script /var/lib/asterisk/agi-bin/testAGI.php
    -- <SIP/101-00000007>AGI Script testAGI.php completed, returning 0


and here is my php agi source code:

#!/usr/bin/php -q
<?php

error_reporting(E_ALL);
ob_implicit_flush(false);
set_time_limit(6);
$stdin = fopen('php://stdin', 'r');
$stdlog = fopen('tmp/agi_log.log', 'w');
$debug = false;
// Read input from Asterisk and output via $astOutput *
function astRead()
{
global $stdin, $debug, $stdlog;
$astOutput = str_replace("\n", "", fgets($stdin, 4096));
if ($debug) fputs($stdlog, "read: $input\n");
return $astOutput;
}
// Write AGI command to Asterisk
function astWrite($agiCommand)
{
global $debug, $stdlog;
if ($debug) fputs($stdlog, "write: $agiCommand\n");
echo $agiCommand."\n";
}
// Handling execution input from Asterisk
while (!feof($stdin))
{
$temp = fgets($stdin);
$temp = str_replace("\n","",$temp);
$s = explode(":",$temp);
$agivar[$s[0]] = trim($s[1]);
if ($temp == "")
{
break;
}
}
// Operational Code starts here

astWrite("STREAM FILE demo-congrats #");
astRead();
astWrite("SAY NUMBER 123456 #");
astRead();

// Finalization of AGI script and clean-ups
fclose ($stdin);
fclose ($stdlog);
exit(0);


as you see, it was return 0. agi is running successful or not?

[from-internal]
exten => _X.,1,NOOP(++++++Invoking AGI Script now(before agi): MGH++++++++)
exten => _X.,2,AGI(testAGI.php)
exten => _X.,3,NOOP(***************After AGI********************)
exten => _X.,100,DeadAGI(getCDRLog.php) 





On Sat, Jan 19, 2013 at 11:49 AM, Salman Zafar <msalman...@gmail.com> wrote:


        You seriously need to go through Asterisk text books available online 
or at-least read the manual.
        
        NoOP is just a No Operation, so its just printing text in your case. 
        
        To execute an AGI you need to call it from dialpan like exten => 
_X.,n,AGI(name_of_AGI), agi should be appropriate directory, which I reckon you 
already know.



        On Sat, Jan 19, 2013 at 1:06 PM, Muhammad <mohammad.ghaz...@gmail.com> 
wrote:
        

                Thanks Steve.
                
                but explain me more about your dialplan codes. Im a beginner.
                
                
                
                exten => _X.,1,NOOP(Invoking AGI Script now)
                
                
                what is "Invoking AGI Script now" and what should I do in this 
method?
                
                what is _X. it seems it is dynamic extension number.
                and "n"?
                
                Thanks
                
                
                On Wed, Jan 16, 2013 at 11:12 AM, SamyGo <govoi...@gmail.com> 
wrote:
                

                        Hi,
                        Please see my comments in line.
                        

                        Regards,
                        Sammy


                        On Wed, Jan 16, 2013 at 12:13 PM, Zohair Raza 
<engineerzuhairr...@gmail.com> wrote:
                        


                                On Wed, Jan 16, 2013 at 11:01 AM, Muhammad 
<mohammad.ghaz...@gmail.com> wrote:
                                

                                        Thanks Zohair!
                                        I wrote some php code to working with 
AGI, but it dosen't work.
                                        

                                        I don't know how can run it. please 
explain me when I put my php code inside /var/lib/asterisk/agi-bin  so, what 
should I do after that. 


                                Make sure Asterisk has access to your AGI 
script, and make it executable (chmod u+x agi.php). Also make sure it has 
shebang (!#/usr/bin/php)


                        Besides  that you'll need to create SIP users and 
define their context=my-agi and in your context call this AGI.

                        [my-agi]
                        exten => _X.,1,NOOP(Invoking AGI Script now)
                        same => n,AGI(my-agi-filename.php)
                        same => n,NOOP(Any other post AGI things here)
                        same => n,Hangup()


                                 

                                        and the second one, how can limit users 
to call just my number in list at database and permit to call another numbers.
                                        
                                        

                                That depends on logic in your script, you can 
also separate users by contexts


                        Alternative to the above approach there are other 
possibilities, like applying a GotoIF() condition in the [my-agi]  dialplan 
code above restricting a particluar number,  or Instead of _X. in the above 
code implement some regex to enable only local area dialing i.e

                        exten => _78XXXXXX,1,NOOP(Invoking AGI Script now for 
dialled string starting with 78 and 8 digit in length)

                        If you don't like any of the above because you've a 
list of numbers which should be dialled only in a DB.table then in your php-AGI 
script do some restrictions based on that table.


                                 

                                        
                                        
                                        On Tue, Jan 15, 2013 at 12:39 PM, 
Zohair Raza <engineerzuhairr...@gmail.com> wrote:
                                        

                                                you need to run full command, 
like 

                                                agi show commands topic answer
                                                agi show commands topic gosub
                                                agi set debug on


                                                Regards,
                                                Zohair Raza


                                                On Tue, Jan 15, 2013 at 1:05 
PM, Muhammad <mohammad.ghaz...@gmail.com> wrote:
                                                

                                                        Hi,
                                                        
                                                        in CLI, I type agi show 
or other agi commad, but response me "command not found".
                                                        How can see agi is work 
normally in my server?
                                                        
                                                        

                                                        --
                                                        
_____________________________________________________________________
                                                        -- Bandwidth and 
Colocation Provided by http://www.api-digital.com --
                                                        New to Asterisk? Join 
us for a live introductory webinar every Thurs:
                                                                       
http://www.asterisk.org/hello
                                                        
                                                        asterisk-users mailing 
list
                                                        To UNSUBSCRIBE or 
update options visit:
                                                           
http://lists.digium.com/mailman/listinfo/asterisk-users
                                                        



                                                --
                                                
_____________________________________________________________________
                                                -- Bandwidth and Colocation 
Provided by http://www.api-digital.com --
                                                New to Asterisk? Join us for a 
live introductory webinar every Thurs:
                                                               
http://www.asterisk.org/hello
                                                
                                                asterisk-users mailing list
                                                To UNSUBSCRIBE or update 
options visit:
                                                   
http://lists.digium.com/mailman/listinfo/asterisk-users
                                                



                                        --
                                        
_____________________________________________________________________
                                        -- Bandwidth and Colocation Provided by 
http://www.api-digital.com --
                                        New to Asterisk? Join us for a live 
introductory webinar every Thurs:
                                                       
http://www.asterisk.org/hello
                                        
                                        asterisk-users mailing list
                                        To UNSUBSCRIBE or update options visit:
                                           
http://lists.digium.com/mailman/listinfo/asterisk-users
                                        



                                --
                                
_____________________________________________________________________
                                -- Bandwidth and Colocation Provided by 
http://www.api-digital.com --
                                New to Asterisk? Join us for a live 
introductory webinar every Thurs:
                                               http://www.asterisk.org/hello
                                
                                asterisk-users mailing list
                                To UNSUBSCRIBE or update options visit:
                                   
http://lists.digium.com/mailman/listinfo/asterisk-users
                                



                        --
                        
_____________________________________________________________________
                        -- Bandwidth and Colocation Provided by 
http://www.api-digital.com --
                        New to Asterisk? Join us for a live introductory 
webinar every Thurs:
                                       http://www.asterisk.org/hello
                        
                        asterisk-users mailing list
                        To UNSUBSCRIBE or update options visit:
                           
http://lists.digium.com/mailman/listinfo/asterisk-users
                        



                --
                
_____________________________________________________________________
                -- Bandwidth and Colocation Provided by 
http://www.api-digital.com --
                New to Asterisk? Join us for a live introductory webinar every 
Thurs:
                               http://www.asterisk.org/hello
                
                asterisk-users mailing list
                To UNSUBSCRIBE or update options visit:
                   http://lists.digium.com/mailman/listinfo/asterisk-users
                




        -- 
        
        Regards
        
        
        **************************
        Muhammad Salman
        ***************************

        --
        _____________________________________________________________________
        -- Bandwidth and Colocation Provided by http://www.api-digital.com --
        New to Asterisk? Join us for a live introductory webinar every Thurs:
                       http://www.asterisk.org/hello
        
        asterisk-users mailing list
        To UNSUBSCRIBE or update options visit:
           http://lists.digium.com/mailman/listinfo/asterisk-users
        


--
_____________________________________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
New to Asterisk? Join us for a live introductory webinar every Thurs:
               http://www.asterisk.org/hello

asterisk-users mailing list
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-users

Reply via email to