title: How do I establish a persistent connection to an Asterisk manager with PHP?
body: <p>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:</p>
  
  <pre><code>/**
   * The parameters for connecting to the server
   */
   $params = array('server' =&gt; '192.168.1.100', 'port' =&gt; '5038');
  
  /**
   * Instantiate Asterisk object and connect to server
   */
   $ast = new Net_AsteriskManager($params);
  
  /**
   * Connect to server
   */
   try {
      $ast-&gt;connect();
   } catch (PEAR_Exception $e) {
      echo $e;
   }
  
   /**
    * Login to manager API
    */
    try {
      $ast-&gt;login('admin', 'abcdefghi');
   } catch(PEAR_Exception $e) {
      echo $e;
   }
  </code></pre>
  
  <p>The above code works, as far as connecting. I'm able to fetch data through it.</p>
  
  <p>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.</p>
  
  <p>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?</p>