Page 252 - Asterisk™: The Future of Telephony
P. 252
Trying your program directly from the operating system may help you to more easily
spot bugs in your program.
Using Asterisk’s agi debug Command
The Asterisk command-line interface has a very useful command for debugging AGI
scripts, which is called (appropriately enough) agi debug. If you type agi debug at an
Asterisk console and then run an AGI, you’ll see something like the following:
-- Executing AGI("Zap/1-1", "temperature.php") in new stack
-- Launched AGI Script /var/lib/asterisk/agi-bin/temperature.php
AGI Tx >> agi_request: temperature.php
AGI Tx >> agi_channel: Zap/1-1
AGI Tx >> agi_language: en
AGI Tx >> agi_type: Zap
AGI Tx >> agi_uniqueid: 1116732890.8
AGI Tx >> agi_callerid: 101
AGI Tx >> agi_calleridname: Tom Jones
AGI Tx >> agi_callingpres: 0
AGI Tx >> agi_callingani2: 0
AGI Tx >> agi_callington: 0
AGI Tx >> agi_callingtns: 0
AGI Tx >> agi_dnid: unknown
AGI Tx >> agi_rdnis: unknown
AGI Tx >> agi_context: incoming
AGI Tx >> agi_extension: 141
AGI Tx >> agi_priority: 2
AGI Tx >> agi_enhanced: 0.0
AGI Tx >> agi_accountcode:
AGI Tx >>
AGI Rx << STREAM FILE temperature ""
AGI Tx >> 200 result=0 endpos=6400
AGI Rx << STREAM FILE is ""
AGI Tx >> 200 result=0 endpos=5440
AGI Rx << SAY NUMBER 67 ""
-- Playing 'digits/60' (language 'en')
-- Playing 'digits/7' (language 'en')
AGI Tx >> 200 result=0
AGI Rx << STREAM FILE degrees ""
AGI Tx >> 200 result=0 endpos=6720
AGI Rx << STREAM FILE fahrenheit ""
AGI Tx >> 200 result=0 endpos=8000
-- AGI Script temperature.php completed, returning 0
You’ll see three types of lines while your AGI script is running. The first type, prefaced
with AGI TX >>, are the lines that Asterisk transmits to your program’s STDIN. The second
type, prefaced with AGI RX <<, are the commands your AGI program writes back to
Asterisk over STDOUT. The third type, prefaced by --, are the standard Asterisk messages
presented as it executes certain commands.
To disable AGI debugging after it has been started, simply type agi no debug at an
Asterisk console.
224 | Chapter 9: The Asterisk Gateway Interface (AGI)