Quantcast
Channel: VOIP-info.org Wiki Changes
Viewing all articles
Browse latest Browse all 5767

Asterisk AGI php

$
0
0
Using PHP with the Asterisk Gateway Interface (AGI)

PHP Tips and Examples

Script Location

Asterisk expects to find scripts in the /var/lib/asterisk/agi-bin/ directory for AGI execution.

File Permissions

Remember to make your files executable with chmod 755 /var/lib/asterisk/agi-bin/*.php .

The Shebang

The first line in your script will of course determine which executable runs it. Be aware of the different versions of PHP, such as /usr/bin/php and /usr/bin/php-cgi. In most cases life will be easier if you use the CLI version— typically at /usr/bin/php. (Use /usr/bin/php -v to confirm that you are using the CLI version.) This will make $argv and $argc available, disable buffering, disable HTTP header output, and pipe error messages to STDERR instead of STDOUT. All these are desirable for working with Asterisk. If you use the CGI executable, you will have to use some command line options and edit your scripts to ensure proper behaviour.
The shebang should be followed immediately by the <?php script opener, with only a newline between them. Any whitespace could get sent to Asterisk, causing problems.

Read AGI Inputs

All communication with the AGI occurs over STDIN and STDOUT; these IO streams are predefined in PHP and do not need to be opened or closed. When your program starts, Asterisk will stream a number of variables to it, which it's in your interest to capture. ...

Viewing all articles
Browse latest Browse all 5767

Trending Articles