5

我正在尝试连接到 Asterisk 管理器界面,但我遇到了代码阻塞问题以及连接持久性问题。以下是我所拥有的,然后是对出现问题的描述:

/**
 * 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;
 }

就连接而言,上面的代码有效。我可以通过它获取数据。

问题是发送查询需要很长时间,当我以实时模式(控制台)观察服务器时,我看到用户管理员在发送输出后正在从服务器注销。

换句话说,即使我没有在代码中明确注销,“管理员”也会被注销。我怎样才能使这个连接持久?

4

2 回答 2

4

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

于 2012-03-17T11:46:24.213 回答
0

我想你只是使用了 php-agi.php 类。它已经拥有你所需要的一切。没必要再写了。

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

于 2012-03-15T07:48:28.123 回答