AGI PHP script not running from dial plan

Hi All,

I’m relatively new to Asterisk so I’m hoping this is an easy question to answer.

I have a dial plan which calls an AGI written in PHP. The only thing I have in the PHP file is a command to initialize a variable called CHECK_STATUS and a command to write to the syslog however it isn’t being run. I’ve changed permissions, ran other commands (I thought maybe the syslog command was faulty) and nothing seems to work.

The Asterisk CLI shows that the call gets to the context but when it tries to run the PHP I get this:
Initiating : Platform: gtv Module: xml_maCheckName execution for session: xxxxx but nothing happens after that and there is no error message.

Here is my PHP:



Here is my dial plan:

exten => _X.,1,Noop(******* BEGIN CODE FOR CHECK NAME *****)
exten => _X.,n,AGI(agiWrapper.agi,gtv^xml_maCheckName )
exten => _X.,n,Noop(
Check Status: ${CHECK_STATUS} ************)
exten => _X.,n,GotoIf($[${CHECK_STATUS} != 200]?TechError)


Also in the noop the $CHECK_STATUS is null.

Can anyone help?



Add below lines in the beginning of PHP file:
$agi = new AGI();

you may also save file with .php extension and try to run from CLI to see if PHP file is running fine.

  1. You need to import the phpagi class, in order to able to use the class’s methods. Also you need to specify the php interpreter path

UNIX shell scripts are set as executable and the first line in the file contains a “shebang” line which shows the path to the executable which will parse the script.

If your distro’s PHP binary is at e.g. /usr/bin/php you would add this to the first line of your script:


  1. The script then needs to be marked as executable.

chmod 0755 /path/to/script.php