title: How to avoid max channels per tcp connection with amqp php, persistent connections and php-fpm
body: <p>I`m just learning rabbitMQ and I ran into a problem.</p>
  
  <p>Using <a href="http://pecl.php.net/package/amqp" rel="noreferrer">http://pecl.php.net/package/amqp</a> version 1.4 (latest now) and RabbitMQ 3.3.1.
  We must use php5-fpm and persistent connections with amqp->pconnect(). </p>
  
  <p>After a while (I guess 65500 requests) a problem occurs halting all writes 
  "</p>
  
  <blockquote>
    <p>Could not create channel. Connection has no open channel slots
    remaining</p>
  </blockquote>
  
  <p>"</p>
  
  <p>From what I have read in the sources is because every tcp connection have an autoincrement channel ID that reaches its max. This happens because every request must use the channel, and is no way to use the same channel ( I could not find a way into the php-amqp channel classs to make it persistent) and scripts cannot communicate ( to use the same instance of the channel as php object).</p>
  
  <p>To lower the php-fpm lifetime is not an option, and either decoupling the application-rabbitmq communication trough another technology/library etc.</p>
  
  <p>Is there any easy way to fix this ? </p>
  
  <p>Theoretically it should be one channel per thread (php5-fpm worker in this case) but how can be achieved using this library ? </p>
  
  <p>The code I`m using now (similar)</p>
  
  <pre><code>$this-&gt;con = new AMQPConnection(array(
      'host'          =&gt; $this-&gt;con_params['host'],
      'port'          =&gt; $this-&gt;con_params['port'],
      'vhost'         =&gt; $this-&gt;con_params['vhost'],
      'login'         =&gt; $this-&gt;con_params['user'],
      'password'      =&gt; $this-&gt;con_params['pass'],
      'read_timeout'  =&gt; 1,//seconds
      'write_timeout' =&gt; 1,//seconds
  'connect_timeout' =&gt; 1,//seconds
  ));
  $this-&gt;con-&gt;pconnect();
  $channel = new AMQPChannel($this-&gt;con);
  $queue = new AMQPQueue($channel);
  $queue-&gt;setName($queueName);
  $queue-&gt;setFlags(AMQP_DURABLE);
  //$queue-&gt;declareQueue();//make sure it exists
  $exchange = new AMQPExchange($channel);
  $exchange-&gt;setName($exchangeName);
  $exchange-&gt;setFlags(AMQP_DURABLE);
  $exchange-&gt;setType(AMQP_EX_TYPE_DIRECT);
  //$exchange-&gt;declareExchange();
  $this-&gt;queues[$queueName]-&gt;bind($exchangeName);
  </code></pre>
  
  <p>Thanks !!</p>