eguvenc / php-amqplib

Automatically exported from code.google.com/p/php-amqplib
GNU Lesser General Public License v2.1
0 stars 0 forks source link

Patch to fix PHP Notices present on PHP 5.3.2 with r28 (+ support for multiple rabbit servers) #20

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Run the demo
2. See "Accessing static property AMQPConnection::$METHOD_MAP as non static" 
error and a message about attempting feof on an object not a socket resource

What is the expected output? What do you see instead?
No errors or notices

What version of the product are you using? On what operating system?
PHP 5.3.2 / php-amqplib r28

Please provide any additional information below.
Patch to fix this is as follows.  Note, this also permits the HOST to be 
specified as an array when calling AMQPConnection, so that failover between 
multiple rabbit servers is possible.

=== modified file 'amqp.inc'
--- amqp.inc    2010-11-19 15:37:30 +0000
+++ amqp.inc    2010-11-19 15:42:14 +0000
@@ -295,7 +295,7 @@
         "library_version" => array('S', "0.1")
     );

-    protected static $METHOD_MAP = array(
+    protected $METHOD_MAP = array(
         "10,10" => "start",
         "10,20" => "secure",
         "10,30" => "tune",
@@ -314,8 +314,6 @@
                                 $connection_timeout = 10,
                                 $read_write_timeout = 3)
     {
-        $this->METHOD_MAP = AMQPConnection::$METHOD_MAP;
-
         if($user && $password)
         {
             $login_response = new AMQPWriter();
@@ -338,10 +336,12 @@

             $errstr = $errno = NULL;
             $this->sock = NULL;
-            if (!($this->sock = 
fsockopen($host,$port,$errno,$errstr,$connection_timeout)))
+            if(!is_array($host)) $host = array($host);
+            foreach ($host as $possiblehost)
             {
-                throw new Exception ("Error Connecting to server($errno): 
$errstr ");
-            }
+               if ($this->sock = 
fsockopen($possiblehost,$port,$errno,$errstr,$connection_timeout)) break;
+           }
+            if (!$this->sock) throw new Exception ("Error unable to connect to 
any hosts. Most recently: ($errno): $errstr ");
             stream_set_timeout($this->sock,$read_write_timeout);
             stream_set_blocking($this->sock, 1);
             $this->input = new AMQPReader(null, $this->sock);
@@ -727,7 +727,7 @@

 class AMQPChannel extends AbstractChannel
 {
-    protected static $METHOD_MAP = array(
+    protected $METHOD_MAP = array(
         "20,11" => "open_ok",
         "20,20" => "flow",
         "20,21" => "flow_ok",
@@ -763,8 +763,6 @@
         debug_msg("using channel_id: " . $channel_id);

         parent::__construct($connection, $channel_id);
-
-        $this->METHOD_MAP = AMQPChannel::$METHOD_MAP;

         $this->default_ticket = 0;
         $this->is_open = false;

=== modified file 'amqp_wire.inc'
--- amqp_wire.inc   2010-11-19 15:37:30 +0000
+++ amqp_wire.inc   2010-11-19 15:42:10 +0000
@@ -299,8 +299,9 @@
             $read = 0;

             $start = time();
-            while($read < $n && !feof($this->sock) &&
-                  (false !== ($buf = fread($this->sock, $n - $read))))
+
+            while($read < $n && !feof($this->sock->sock) &&
+                  (false !== ($buf = fread($this->sock->sock, $n - $read))))
             {
                 if ($buf == '')
                 {

-bash-3.1$ 

Original issue reported on code.google.com by rtshils...@gmail.com on 19 Nov 2010 at 3:46