Asterisk manager and PHP client


Jump to: navigation, search
  • Asterisk Manager Interface (AMI) allows a client program to connect to an Asterisk instance and issue commands
  • Edit the file "/etc/asterisk/manager.conf":
  • vi /etc/asterisk/manager.conf;

and in the end of the file

secret = mycode
read = system,call,log,verbose,command,agent,user
write = system,call,log,verbose,command,agent,user

restart asterisk using "core restart now"

PHP script to contact Asterisk Manager

creat the following php file:

<html><head></head><body><?php $socket = fsockopen("","5038", $errno, $errstr, 10); if (!$socket) { echo "$errstr ($errno)\n"; } else { fputs($socket, "Action: Login\r\n"); fputs($socket, "UserName: myasterisk\r\n"); fputs($socket, "Secret: mycode\r\n\r\n"); fputs($socket, "Action: Command\r\n"); fputs($socket, "Command: sip show peers\r\n\r\n"); fputs($socket, "Action: Logoff\r\n\r\n"); while (!feof($socket)) { echo fgets($socket).'<br>'; } fclose($socket); } ?> </body> </html>

Personal tools