Question

I'm attempting to connect to an Asterisk manager interface, and I'm having a problem with the code blocking, as well as connection persistence. Below is what I have, followed by a description of what's going wrong:

/**
 * The parameters for connecting to the server
 */
 $params = array('server' => '192.168.1.100', 'port' => '5038');

/**
 * Instantiate Asterisk object and connect to server
 */
 $ast = new Net_AsteriskManager($params);

/**
 * Connect to server
 */
 try {
    $ast->connect();
 } catch (PEAR_Exception $e) {
    echo $e;
 }

 /**
  * Login to manager API
  */
  try {
    $ast->login('admin', 'abcdefghi');
 } catch(PEAR_Exception $e) {
    echo $e;
 }

The above code works, as far as connecting. I'm able to fetch data through it.

The issue is sending a query is taking quite long time, and when I observe the server in realtime mode (console) I see that the user admin is getting log out from server after output is sent.

In other words, 'admin' is getting logged out even though I have not explicitly logged out in the code. How can I make this connection persistent?

Was it helpful?

Solution

Asterisk AMI does not automatically closes the connection however it is network layer who does it, when it detect no activity for long time (=timeout) it drops the connection. To make a connection persistence it is required to keep it busy (=keep alive), whenever connection is idle your application should send keep alive packets to destination server at specified interval (=TTL). We can use any type of command as keep alive packet like in asterisk you can use "Ping".

However if you are looking some existing ready to use solution then you can use some AMI Proxy for that. here are some known AMI proxies

OTHER TIPS

I think you just have use php-agi.php class. it already have all you need. No any need write it again.

php-agi.php distributed with any asterisk and can be found in /var/lib/asterisk/agi-bin/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top