O'Reilly logo

Asterisk: The Future of Telephony by Leif Madsen, Jared Smith, Jim Van Meggelen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Debugging in AGI

Debugging AGI programs , as with any other type of program, can be frustrating. Luckily, there are two advantages to debugging AGI scripts. First, since all the communications between Asterisk and the AGI program happen over STDIN and STDOUT (and, of course, STDERR), you should be able to run your AGI script directly from the operating system. Second, Asterisk has a handy command for showing all the communications between itself and the AGI script: agi debug.

Debugging from the Operating System

As mentioned above, you should be able to run your program directly from the operating system to see how it behaves. The secret here is to act just like Asterisk does, providing your script with the following:

  • A list of variables and their values, such as agi_test:1.

  • A blank line feed (/n) to indicate that you’re done passing variables.

  • Responses to each of the AGI commands from your AGI script. Usually, typing 200 response=1 is sufficient.

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required