phpsocketsasteriskasteriskami

Asterisk AMI returning incorrect data


When running:

asterisk*CLI>queue show <queue-name>

from the terminal I get the expected output (in this case I am expecting to get A:2 within the returned information.

But when I connect to AMI via a PHP socket on the same server I get A:0 (the information has not populated correctly).

$data = '';
$socket = fsocketopen('127.0.0.1', '5038');

fputs($socket, "Action: Login\r\n");
fputs($socket, "UserName: username\r\n");
fputs($socket, "Secret: password\r\n\r\n");
fputs($socket, "Action: QueueStatus\r\n");
fputs($socket, "Action: Logoff\r\n\r\n");

while(!feof($socket)) {
    $data .= fread($socket, 8192);
}

fclose($socket);

$data = trim($data); // This string contains A:0 where I would expect A:2.

The AMI user being used has the correct read permissions in manager.conf and it authenticating successfully.

[username]
secret = password
deny=0.0.0.0/0.0.0.0
permit=127.0.0.1/255.255.255.0
read = system,call,log,verbose,command,agent,user,all
write = system,call,log,verbose,command,agent,user,all

My question is, why would AMI return different information from what the console is returning?

As a side note, this issue also arises when using AMI to run:

asterisk*CLI>sip show peers

The console is returning the correct information while AMI is returning (Unspecified) for each IP address.


Solution

  • So my system administrator took a look. It seems that the machine was holding onto an older Asterisk process on port 5038. After killing that process and starting Asterisk up again AMI was successfully able to retrieve the correct information.